脚本说明:第一步:把如下代码加入区域中here separated by spaces^A great search engine from the makers of AOL!*http://java2000.126.com~java2000 collections|java javascript search html download cgi perl dhtml games activex 下载 脚本^coolest java and javascript collections for internet surfers to enhance web page!*http://www.javagoodies.com/~javagoodies|ActiveX ASP C/C++ CGI Databases java javascript^coolest javagoodies!*'> <br><!--<br/>version = 1.0;<br/>// --><br><br><!--<br/>version = 1.1;<br/>// --><br><br><!--<br/>// When set to true, searching for "fun*y" matches in the string "fun sky".<br/>// (it will also match the string "fun and here is some long dummy text for you"<br/>// which is obviously not what they were looking for, so we suggest you set<br/>// match_across_word_boundaries to false)<br/>// When set to false, the * operator will not match across word boundaries so<br/>// the above example will not match.<br/>match_across_word_boundaries = false; // false is suggested strongly</p><p><br/></p><p><br/>// ************ NO NEED TO MODIFY ANYTHING BELOW THIS POINT ************</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 = title;<br>this.keywords = 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 { // error reading amorphous database<br/>if (pos+30 <= amorphous.length)<br/>alert('Error reading in amorphous database around "'<br/>+ amorphous.substring(pos,pos+30) + '"');<br/>pos = amorphous.indexOf("*",pos) + 1;<br/>}<br/>}<br/>return this;<br/>}<br/>var array = new Object();<br/>array_length = 0; // Netscape 2 fix<br/>var position = 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 = "(((position[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) { // try pattern again in new spot<br>n--;<br>start_pos += back_up_pos+1;<br>} else { // not found<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/>function entry() {<br/>if ((document.entryform.keyword.value.length == 0)<br/>|| (document.entryform.keyword.value == " ")) {<br/>alert("First you must enter a keyword to search for.");<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 (version >= 1.1) {<br>search(document.entryform.keyword.value);<br>if (menu_length == 0)<br>menu[menu_length++] = new Page("","Not found!","");<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.length > 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>amorphous += "* ";<br>else<br>amorphous += " "; // amorphous database must have characters after last asterisk</p> <p>database_length = 0; // Netscape 2 fix<br>var database = new Database(); // read in from amorphous 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 = "or";<br>}<br>search(string);<br>}<br>document.write('<form name="entryform" class="pt9" onSubmit="return entry()">'<br>+'Search for: <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=="and"?" selected":"")+'>AND查询 '<br>+'(AND)<option'+(and_search=="or"?" selected":"")+'>OR查询 '<br>+'(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 <= 1))<br/>document.write('<option value="" class="pt9">Enter a search keyword above\n');<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=" Go There "></form>');<br>// --><br> 以上就是站内搜索脚本例子四(javascript)_Javascript教程的内容,更多相关内容请关注PHP中文网(www.php.cn)