一段javascript的頁面搜尋代碼

來源:互聯網
上載者:User
javascript|頁面 /*
搜尋文字核心程式,仿CRL+F,但功能更強的搜尋
*/
<!--
var iFlag;
function search() {
var wPopupElements=wPopup.document.all;
if (wPopupElements.textcase.checked)
  {iFlag=4;}
else
  {iFlag=0;}
if (wPopupElements.searchtext.value==null || wPopupElements.searchtext.value=='')
  {
   wPopup.alert("請輸入你要尋找的文字");
   return;
  }
if (rng.findText(wPopupElements.searchtext.value,10000,iFlag)==true)
  {
   rng.select();
   rng.scrollIntoView();
   rng.moveStart("character");
  }
else
  {wPopup.alert("已尋找到文檔底部");}
}

function replace() {
var wPopupElements=wPopup.document.all;
if (wPopupElements.textcase.checked)
  {iFlag=4;}
else
  {iFlag=0;}
if (wPopupElements.searchtext.value==null || wPopupElements.searchtext.value=='')
  {
   wPopup.alert("請輸入你要替換的文字");
   return;
  }
if (rng.findText(wPopupElements.searchtext.value,-10000,iFlag)==true)
  {
   rng.text = wPopupElements.replacetext.value;
  }
else
  {wPopup.alert("已替換到文檔底部");}
}

function replaceall() {
var rng = document.body.createTextRange();
var wPopupElements=wPopup.document.all;
if (wPopupElements.textcase.checked)
  {iFlag=4;}
else
  {iFlag=0;}
if (wPopupElements.searchtext.value==null || wPopupElements.searchtext.value=='')
  {
   wPopup.alert("請輸入你要替換的文字");
   return;
  }
  for (i=0; rng.findText(wPopupElements.searchtext.value,10000,iFlag)!=false; i++)
  {
   rng.scrollIntoView();
   rng.text = wPopupElements.replacetext.value;
  }
  setTimeout('wPopup.alert("共有"+i + " 項被替換")',200);
}
//-->


/*
彈出搜尋視窗程序
*/
<!--
function gofind() {
wPopup=window.open('about:blank','','width=300 height=108 left=350 top=200 menubar=no resizeable=no scrollbars=no toolbar=no');
var wPopupDoc=wPopup.document;
wPopupDoc.open();
wPopupDoc.write('<html>\n');
wPopupDoc.write('<head>\n');
wPopupDoc.write('<title>文字搜尋功能</title>\n');
wPopupDoc.write('<style>\n');
wPopupDoc.write('* {font-size:11px;font-family:"Tahoma","Verdana","Arial"}\n');
wPopupDoc.write('button {width:80}\n');
wPopupDoc.write('</style>\n');
wPopupDoc.write('</head>\n');
wPopupDoc.write('<body bgcolor="buttonface" leftmargin="0" topmargin="0">\n');
wPopupDoc.write('<table width="300" height="108" border="0" cellspacing="0" cellpadding="3" bgcolor="#F1F2DF">\n');
wPopupDoc.write('<tr>\n');
wPopupDoc.write('<td>尋找:</td>\n');
wPopupDoc.write('<td><input type="text" name="searchtext" ></td>\n');
wPopupDoc.write('<td><button accesskey="S" name="searchbutton" >尋找</button></td>\n');
wPopupDoc.write('</tr>\n');
wPopupDoc.write('<tr>\n');
wPopupDoc.write('<td>替換:</td>\n');
wPopupDoc.write('<td><input type="text" name="replacetext"></td>\n');
wPopupDoc.write('<td><button accesskey="R" name="replacebutton" >替換</button></td>\n');
wPopupDoc.write('</tr>\n');
wPopupDoc.write('<tr>\n');
wPopupDoc.write('<td colspan="2"><input type="checkbox" name="textcase" value="textcase">區分大小寫</td>\n');
wPopupDoc.write('<td><button accesskey="A" name="replaceallbutton" >替換全部</button></td>\n');
wPopupDoc.write('</tr>\n');
wPopupDoc.write('<tr>\n');
wPopupDoc.write('<td colspan="2"> </td>\n');
wPopupDoc.write('<td><button accesskey="C" name="cancelbutton" >關閉</button></td>\n');
wPopupDoc.write('</tr>\n');
wPopupDoc.write('</table>\n');
wPopupDoc.write('</body>\n');
wPopupDoc.write('</html>\n');
wPopupDoc.close();
}
//-->


相關文章

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。