|
 |
来自MyIE2插件的页面文字查找 |
|
 |
<html> <head> <title> New Document </title> <script language="javascript">
function strip(x,c) { while (x.substring(0,1) == c) x = x.substring(1); while (x.substring(x.length-1,x.length) == c) x = x.substring(0,x.length-1); return x; }
function search() { var r,i,s; s=window.document.selection.createRange().text; if(!s) { s=prompt('Enter text to highlight:',''); } else { s=strip(s,' '); window.document.selection.empty(); }
if(s) { r=window.document.body.createTextRange(); for(i=0;r.findText(s);i++) { r.execCommand("BackColor","","yellow"); r.execCommand("ForeColor","","red"); r.execCommand("Bold","",""); r.collapse(false); } if (i==0) { alert('\"'+ s +'\"\r\n not found on this page'); } else { if (i==1) sm=' occurrence'; else sm=' occurrences';
status='TextHighlighter : '+i+sm+' of \"' + s + '\" highlighted';
window.clipboardData.setData("Text",s); } } } </script> </head>
<body> 点击一链接弹出promot,输入文字,点击确定后,如何实现CTRL+F全文查找的功能,如果网页中有promot的文字,就被选中,否则弹出没有的信息ALERT <button onclick=search()>Search</button> </body> </html>
缺缺 发表于 2004-7-23 [所属栏目: JScript | 返回首页]
|
|
|