MozTW 討論區 https://forum.moztw.org/ |
|
能讓Find as you Type支援Regular Expression嗎 https://forum.moztw.org/viewtopic.php?f=2&t=2088 |
第 1 頁 (共 1 頁) |
發表人: | 訪客 [ 2004-02-26, 17:04 ] |
文章主題 : | 能讓Find as you Type支援Regular Expression嗎 |
目前有什麼擴充套件可以實作出來嗎 或是會在未來的版本直接加入 或是根本就不實用? 麻煩各位前輩解感:) |
發表人: | 訪客 [ 2004-02-26, 18:11 ] |
文章主題 : | |
與其讓Find as you Type支援Regular Expression, 不如建議你用[url=javascript:(function(){var count=0, text, regexp;text=prompt("Search regexp:", "");if(text==null || text.length==0)return;try{regexp=new RegExp("(" + text +")", "i");}catch(er){alert("Unable to create regular expression using text '"+text+"'.\n\n"+er);return;}function searchWithinNode(node, re){var pos, skip, spannode, middlebit, endbit, middleclone;skip=0;if( node.nodeType==3 ){pos=node.data.search(re);if(pos>=0){spannode=document.createElement("SPAN");spannode.style.backgroundColor="yellow";middlebit=node.splitText(pos);endbit=middlebit.splitText(RegExp.$1.length);middleclone=middlebit.cloneNode(true);spannode.appendChild(middleclone);middlebit.parentNode.replaceChild(spannode,middlebit);++count;skip=1;}}else if( node.nodeType==1 && node.childNodes && node.tagName.toUpperCase()!="SCRIPT" && node.tagName.toUpperCase!="STYLE"){for (var child=0; child < node.childNodes.length; ++child){child=child+searchWithinNode(node.childNodes[child], re);}}return skip;}window.status="Searching for "+regexp+"...";searchWithinNode(document.body, regexp);window.status="Found "+count+" match"+(count==1?"":"es")+" for "+regexp+".";})();]Bookmarklets[/url]更實際. 因為Find As You Type不方便顯示所有符合的條件. 每次都需要按F3才能顯示下一個符合的字串. |
發表人: | 訪客 [ 2004-02-26, 18:13 ] |
文章主題 : | |
抱歉, 上面的post出現問題了. 與其讓Find as you Type支援Regular Expression, 不如建議你用 代碼: javascript:(function(){var count=0, text, regexp;text=prompt("Search regexp:", "");if(text==null || text.length==0)return;try{regexp=new RegExp("(" + text +")", "i");}catch(er){alert("Unable to create regular expression using text '"+text+"'.\n\n"+er);return;}function searchWithinNode(node, re){var pos, skip, spannode, middlebit, endbit, middleclone;skip=0;if( node.nodeType==3 ){pos=node.data.search(re);if(pos>=0){spannode=document.createElement("SPAN");spannode.style.backgroundColor="yellow";middlebit=node.splitText(pos);endbit=middlebit.splitText(RegExp.$1.length);middleclone=middlebit.cloneNode(true);spannode.appendChild(middleclone);middlebit.parentNode.replaceChild(spannode,middlebit);++count;skip=1;}}else if( node.nodeType==1 && node.childNodes && node.tagName.toUpperCase()!="SCRIPT" && node.tagName.toUpperCase!="STYLE"){for (var child=0; child < node.childNodes.length; ++child){child=child+searchWithinNode(node.childNodes[child], re);}}return skip;}window.status="Searching for "+regexp+"...";searchWithinNode(document.body, regexp);window.status="Found "+count+" match"+(count==1?"":"es")+" for "+regexp+".";})(); 更實際.
因為Find As You Type不方便顯示所有符合的條件. 每次都需要按F3才能顯示下一個符合的字串. |
發表人: | 訪客 [ 2004-02-26, 18:15 ] |
文章主題 : | |
上面是一個Bookmarklet, 將它當網址儲存成Bookmark來用就可以了. |
發表人: | 訪客 [ 2004-02-28, 12:32 ] |
文章主題 : | |
感謝! 真是太讚了~:) |
第 1 頁 (共 1 頁) | 所有顯示的時間為 UTC + 8 小時 |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |