程
式
範
例
擷取反白文字
(在網頁中,拖曳反白文字試試!)
原始碼說明:
一 將下面的原始碼加到<head>區
<SCRIPT LANGUAGE="JavaScript">
<!--
var text = "";
function getActiveText(e)
{
// Sets text MSIE or Netscape active
// text based on browser, puts text in form
text = (document.all) ? document.selection.createRange().text : document.getSelection();
document.theform.text.value = text;
return true;
}
document.onmouseup = getActiveText;
if (!document.all) document.captureEvents(Event.MOUSEUP);
// -->
</script>
二 將下面的原始碼加到<body>區
<center>
<form name=theform>
您所選擇的文字是:<input type=text
name=text value=""> <!--文字
-->
</form>
</center>
使用說明:
1.取得相關原始碼,用"記事本"開啟。
2.修改藍色部分後,再貼到指定的位置即可。
3.您可以在文字框中加入 size 屬性,設定它的大小。
4.本例是以文字框為例,您也可以用文字區塊。
5.IE的使用者,它也可以從別的文字框及文字區塊中擷取到您想要的文字。(自行測試!)
6.可以將本頁"另存新檔",作為修改時的參考。
本站範例程式來自各地資源,如有侵權,請來函告知。
-- 網奕工坊 -- 站長信箱: tn705939@ms7.tisnet.net.tw