[vbscript][javascript]如何取得被選取的區域文字
發表於 : 2008年 11月 27日, 10:54
利用 document.selection 來進行, 並利用 createRange() 方法產生選取區塊物件後, 利用 text 屬性讀出內容, 範例如下:
參考:
http://www.blueshop.com.tw/board/show.a ... 6152641OLG
http://www.microsoft.com/technet/script ... y0106.mspx
代碼: 選擇全部
<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