日期:2014-05-16 浏览次数:20368 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> </head> <body> <textarea id="textarea" />hello my world</textarea> <br/> <input type="text" id="find_string" height="10px" /> <input type="button" value="find" onclick="find()"/> <script> function find(){ var text=document.getElementById('textarea').value; var find_string=document.getElementById("find_string").value; var j=find_string.length; var len=text.length; for(var i=0;i<len-j;i++){ var son_string=text.substring(i,i+j); if(son_string==find_string){ if(document.getElementById('textarea').setSelectionRange){ document.getElementById('textarea').setSelectionRange(i,i+j);}//ff else {//ie var range =document.getElementById('textarea').createTextRange(); range.collapse(true); range.moveStart('character',i); range.moveEnd('character',j); range.select(); } break; } } } </script> </div> </body> </html>
------解决方案--------------------
暂时只能查询一处,可以加上下一个等命令完善。。。