看板 Web_Design 關於我們 聯絡資訊
※ 引述《shga (我愛慢慢跑)》之銘言: : ※ 引述《Falldog (嘿嘿~)》之銘言: : 可以做出一個欄位 : 讓user填入該頁面想查尋的字串 : 就可以做出類似ctrl+f的功能? : 找到本頁 該字串的位置 : 不用到資料庫 : 可以嗎? 可以 <script> var n=0; var hasNext=false; function findStr(str){ txt=document.body.createTextRange(); if(txt.findText(str)){ for(var i=0;i<n & (hasNext=txt.findText(str));i++){ txt.moveStart("character",1); txt.moveEnd("textedit"); } if(hasNext){ txt.moveStart("character",-1); txt.moveEnd("textedit"); txt.findText(str); txt.select(); txt.scrollIntoView(); n++; }else{ alert('搜尋到底了'); n=0; findStr(str); } }else{ alert('找不到'+str); } } </script> 0123456789012345678901234567890123456789<br /> <input type="text" id="s" /> <input type="button" onclick="findStr(document.getElementById('s').value)" value="search" /> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.162.203.90
enjoylife98:漂亮 10/31 00:25