//W3C/1. Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
資訊取得方式。 「百度」二字源自中國宋朝詞人辛棄疾的《青玉案·元夕》詞句“眾裡尋他千百度”,象徵著百度對中文資訊檢索技術的執著追求。
<script> <BR>function highlight(idVal, keyword) { <BR>var textbox = document.getElementById(idVal); <BR>if (" " ==document.getElementById(idVal); <BR>if (" " ==document.getElementById(idVal); <BR>if (" " ==document.getElementById(idVal); <BR>if (" " ==花keyword) return; <BR>//取得所有文字內容<BR>var temp = textbox.innerHTML; <br>console.log(temp); <br>var htmlReg = new RegExp("<.* ?>", "i"); <BR>var arr = new Array(); <BR><BR>//取代HTML標籤<BR>for (var i = 0; true; i ) { <BR> //符合html標籤<BR>var tag = htmlReg.exec(temp); <BR>if (tag) { <BR>arr[i] = tag; <BR>} else { <BR>break; <br> } <br>temp = temp.replace(tag, "{[(" i ")]}"); <BR>} <BR><br><br>// 講關鍵字拆分併入數組<BR>words = decodeURIComponent( keyword.replace(/,/g, ' ')).split(/s /); <BR><BR>//取代關鍵字<BR>for (w = 0; w < words .length; w ) { <BR>// 符合關鍵字,保留關鍵字中可以出現的特殊字元<br>var r = new RegExp("(" words[w].replace(/[(){}. *?^$|\ []]/g, "\$&") ")", "ig"); <br>temp = temp.replace(r, "<b style='color:Red;' >$1" ); <BR>} <BR><BR>//恢復HTML標籤<BR>for (var i = 0; i < arr.length; i ) { <BR>temp = temp.replace("{[(" i ")]}", arr[i]); <BR>} <BR>textbox.innerHTML = temp; <BR>} <BR>highlight("textbox","百度,李彥宏"); <BR>< /script> </script>