Re: [問題] 可以只針對本頁面搜尋嗎? 不用用到資料庫

看板Web_Design作者 (Benny)時間19年前 (2006/10/25 03:30), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串3/3 (看更多)
※ 引述《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

10/31 00:25, , 1F
漂亮
10/31 00:25, 1F
文章代碼(AID): #15FcdPl9 (Web_Design)
文章代碼(AID): #15FcdPl9 (Web_Design)