[vbscript][javascript]如何取得被選取的區域文字

有關網頁及相關語法的討論
回覆文章
頭像
tim
文章: 1380
註冊時間: 2008年 11月 26日, 00:49

[vbscript][javascript]如何取得被選取的區域文字

文章 tim »

利用 document.selection 來進行, 並利用 createRange() 方法產生選取區塊物件後, 利用 text 屬性讀出內容, 範例如下:

代碼: 選擇全部

<html>
<body>
<script language=vbscript>
function test() 
 Set objSelection = Document.Selection.CreateRange()
 Msgbox objSelection.text
end function
</script>
<script language=javascript>
function test2() 
{
 alert(document.selection.createRange().text);
}
</script>
this is a test string!!
<input type=button value="show select" onclick="test()">
<input type=button value="show select2" onclick="javascripttest2();">
</body>
</html>


參考:
http://www.blueshop.com.tw/board/show.a ... 6152641OLG
http://www.microsoft.com/technet/script ... y0106.mspx
多多留言, 整理文章, 把經驗累積下來.....
回覆文章