脚本说明:第一步:如下代码追加領域中 <br><!--<br/>version = 1.0;<br/>// --><br><br>< ;!--<br>version = 1.1;<br>// --><br><br><!--<br/>// true に設定すると、「」を検索しますfun*y" は文字列 "fun sky" に一致します。<br/>// (文字列 "fun and here is some 長いダミー テキストをあなたに提供します" にも一致します<br/>// これは明らかに彼らが探していたものではないので、 set<br/>// match_across_word_boundaries を false) にすることをお勧めします<br/>// false に設定すると、* 演算子は単語の境界を越えて一致しないため、<br/>// 上の例は一致しません。<br/>match_across_word_boundaries = false; // false を強く推奨します</p><p><br/></p><p><br/>// ************ この点より下は何も変更する必要はありません ************</p><p>function Page(url,title,keywords) {<br/>while ((url.length > 0) && (url.charAt(0) == " ")) {<br/>url = url.substring(1,url.length) ;<br/>}<br/>this.url = url;<br/>while ((title.length > 0) && (title.charAt(0) == " ")) {<br>title = title.substring(1,title.length); <br>}<br>this.title = タイトル;<br>this.keywords = キーワード;<br>return this;<br>}<br>function Database() {<br>var pos = 0;<br>while ((pos1 = amorphous.indexOf("~",pos) ) != -1) {<br>pos2 = amorphous.indexOf("|",pos1+1);<br>pos3 = amorphous.indexOf("*",pos2+1);<br>if ((pos2 != -1)<br> && (pos2 < pos3) && (pos3 <= amorphous.indexOf("*",pos))) {<br/>this[database_length++] = new Page(amorphous.substring(pos,pos1),<br/>amorphous.substring(pos1) +1,pos2),<br/>amorphous.substring(pos2+1,pos3));<br/>pos = pos3+1;<br/>} else { // 非晶質データベースの読み取りエラー<br/>if (pos+30 <= amorphous.length)<br/> alert('"'<br/>+ amorphous.substring(pos,pos+30) + '"' 付近の非晶質データベースの読み取りエラー);<br/>pos = amorphous.indexOf("*",pos) + 1;<br/>}<br/>}<br/>これを返す;<br/>}<br/>var array = new Object();<br/>array_length = 0; // Netscape 2 fix<br/>varposition = new Object();<br/>position_length = 0; // Netscape 2 fix<br/>function pattern(str) {<br/>array_length = Position_length = 0;<br/>while ((str.length > 1) && (str.charAt(0) == "*")) {<br/>str = str .substring(1,str.length);<br/>}<br/>while ((str.length > 1) && (str.charAt(str.length-1) == "*")) {<br/>str = str.substring( 0,str.length-1);<br/>}<br/>if (str == "*")<br/>return "(true)";<br/>if (str.indexOf("*") == -1) {<br/>array[array_length++ ] = str;<br/>pat = "(combo.indexOf(array[0]) != -1)";<br/>} else {<br/>left = right = 0;<br/>pat2 = "";<br/>pat = "((位置[0] = combo.indexOf(array[0])) != -1)";<br/>while ((right = str.indexOf("*",left)) != -1) {<br/>array[array_length++] = str.substring(left,right);<br/>pat += " && (position["+(position_length)+"] < (position["<br/>+(++position_length)+"] = combo.indexOf(array[" +(array_length)<br/>+"],position["+(position_length-1)+"]+array["+(array_length-1)+"].length"+")))";<br/>if (!match_across_word_boundaries) <br/>pat2 = " && (no_back_up = ((back_up_pos += combo.substring("<br/>+"temp_pos = back_up_pos = Position["<br/>+(position_length-1)+"]+array["+(array_length-1)+" ].length,position["<br/>+ (position_length) + "]).lastIndexOf(' ')) < temp_pos))" + pat2;<br/>left = right+1;<br/>}<br/>array[array_length++] = str.substring(left,str.length);<br/>pat += pat2+")";<br/>}<br/>return pat;<br/>} <br/>function search(str) {<br/>menu_length = 0;<br/>temp = new Object();<br/>temp_length = 0;<br/>words_length = 0;<br/>words = new Object();<br/>pos = 0;<br/>while ((pos = str) .indexOf(" ")) != -1<br/>&& and_search != "exact") {<br/>words[words_length] = str.substring(0,pos);<br/>if (words[words_length].length > 0)<br/> Words_length++;<br/>if (str.length == 1)<br/>str="";<br/>else<br/>str = str.substring(pos+1,str.length);<br/>}<br/>if (str.length > 0)<br/>words [words_length++] = str;<br/>for (q=0;q<words_length;q++) {<br/>temp_length = 0;<br/>str = Words[q].toLowerCase();<br/>pattern_string = pattern(str);<br/>start_pos = back_up_pos = 0;<br/>len = (and_search=="and"&&q>0?menu_length:database_length);<br>for (n=0; n<len; n++) {<br/>no_back_up = true;<br/>position_length = 0;<br/>if (and_search= ="and"&&q>0) {<br/>combo = (menu[n].title + " " + menu[n].keywords).toLowerCase();<br/>} else {<br/>combo = (database[n].title + " " +database[n].keywords).toLowerCase();<br/>}<br/>combo = combo.substring(start_pos,combo.length);<br/>if (eval(pattern_string)) { // found<br/>temp[temp_length++] = ( and_search=="and"&&q>0?menu[n]:database[n]);<br>start_pos = 0;<br>} else if (!no_back_up) { // 新しい場所でパターンを再試行します<br>n--;<br>start_pos += back_up_pos+1;<br>} else { // 見つかりません<br>start_pos = 0;<br>}<br>}<br>if (and_search!="and" && q>0) {<br>added = 0;<br>for (i=0; i<temp_length;i++) {<br/>duplicate = false;<br/>for (j=0;j<menu_length&&!duplicate;j++) {<br/>if (menu[j] == temp[i]) {<br/>duplicate = true;<br/>} <br/>}<br/>if (!duplicate)<br/>menu[menu_length+(added++)] = temp[i];<br/>}<br/>menu_length += added;<br/>} else {<br/>for(h=0;h<temp_length;h++)<br/>menu[ h] = temp[h];<br/>menu_length = temp_length;<br/>}<br/>}<br/>}<br/>functionentry() {<br/>if ((document.entryform.keyword.value.length == 0)<br/>|| (document.entryform.keyword.value == " ")) {<br/>alert("まず、検索するキーワードを入力する必要があります。");<br/>return false;<br/>}<br/>and_search = (document.entryform.and_or.selectedIndex = = 0?"and":"or");<br/>if (document.entryform.and_or.selectedIndex == 2)<br/>and_search = "exact";<br/>if (バージョン >= 1.1) {<br/>search(document.entryform.キーワード.値);<br/>if (menu_length == 0)<br/>menu[menu_length++] = new Page("","見つかりません!","");<br/>document.display.found.options.length = menu_length;<br/>for (n=0; n<menu_length; n++) {<br/>if (menu[n].title.length <= 50)<br/>document.display.found.options[n].text = menu[n].title;<br/> else<br/>document.display.found.options[n].text = menu[n].title.substring(0,50);<br/>document.display.found.options[n].value = menu[n].url; <br/>}<br/>} else {<br/>location.href = location.pathname + "?"<br/>+escape(document.entryform.keyword.value)<br/>+ (and_search != "or"?"&"+and_search:""); <br/>}<br/>return false;<br/>}<br/>function go_there() {<br/>sel = document.display.found.selectedIndex;<br/>if ((sel != -1) && (document.display.found.options[sel].value.長さ> 0))<br/>location.href = document.display.found.options[sel].value;<br/>}</p><p>var amorphous = document.database.list.value;<br/>temp_str = amorphous.substring(amorphous.length-2,amorphous .length);<br/>if (temp_str.indexOf("*") == -1)<br/>アモルファス += "* ";<br/>else<br/>アモルファス += " "; // 非晶質データベースには最後のアスタリスクの後に文字が必要です</p><p>database_length = 0; // Netscape 2 fix<br/>var データベース = new Database(); // 非晶質データベースから読み込みます</p><p>menu_length = 0; // Netscape 2 fix<br/>var menu = new Object();</p><p>string = "";<br/>and_search = "or";<br/>if (location.search.length > 1) {<br/>string = unescape(location.search. substring(1,location.search.length));<br/>pos = 0;<br/>while ((pos = string.indexOf('"',pos)) != -1) {<br/>string = string.substring(0,pos) ) + '\"' + string.substring(pos+1,string.length);<br/>pos += 2;<br/>}<br/>if (string.substring(string.length-4,string.length) == "&and" ) {<br/>string = string.substring(0,string.length-4);<br/>and_search = "and";<br/>} else if (string.substring(string.length-6,string.length) == "&exact") {<br/>string = string.substring(0,string.length-6);<br/>and_search = "exact";<br/>} else if (string.substring(string.length-3,string.length) == "&or") { <br/>string = string.substring(0,string.length-3);<br/>and_search = "または";<br/>}<br/>search(string);<br/>}<br/>document.write('<form name="entryform" class=" pt9" onSubmit="returnentry()">'<br>+'検索: <input type="text" type="pt9" size=15 name="keyword" value="'+string+'"> '<br>+'<input type="button" class="pt9" value="Search" onClick="entry()"><br><select name="and_or" '<br/>+'size=1> ;<option'+(and_search=="or"?" selected":"")+'>AND查询 '<br>+'(AND)<option selected :></option>+'(OR)<option'+(and_search=="exact"?" selected":"")+'>完全'<br>+'適合</ select><br>""通字を使用できます</form><br>'<br>+'<form name="display"><select name="found" size=5>n'); <br>for (n=0; n<menu_length; n++)<br/>document.write('<option value="'+menu[n].url+'">'+menu[n].title+'n');<br>if ((menu_length == 0) && ( location.search.length document.write('<option value="" class="pt9">上記の検索キーワードを入力してください');<br>else if ((menu_length == 0) && (location.search.length > 1))<br>document.write('<option value="">关键字"'<br>+location.search.substring(1,location.search.length)+'"没有発行!n');<br>document.write('</select><br><input type="button" class="pt9" onClick="go_there()" '<br/>+'value=" そこに移動"></form>');<br>// --><br> 以上は站内搜索脚本例子四(javascript)_Javascript教程の内容,更多相关内容请关注PHP中文网(www.php.cn)