首頁 > web前端 > js教程 > 站內搜尋腳本範例四(javascript)_Javascript教程

站內搜尋腳本範例四(javascript)_Javascript教程

黄舟
發布: 2016-12-21 15:37:03
原創
1080 人瀏覽過

腳本說明:
第一步:把如下程式碼加入

區域中



 
version = 1.0;
// -->
腳本>

version = 1.1;
// -->



// ************ 無需修改此點以下的任何內容*********** *

function Page(url,title,keywords) {
while ((url.length > 0) && (url.charAt(0) == " ")) {
url = url.substring(1,url.length) ;
}
this.url = url;
while ((title.length > 0) && (title.charAt(0) == " ")) {
title = title.substring(1,title.length);
title = title.substring(1,title.length);
}
this.title = title;
this.keywords = keywords;
return this;
}
function Database() {
var pos = 0;
while ((pos1 = foam.indexOf(",,,indexOf(",, ))) != -1) {
pos2 = 無定形.indexOf("|",pos1+1);
pos3 = 無定形.indexOf("*",pos2+1);
if ((pos2 != -1)
&& (pos2 this[database_length++] = new Page(amorphous.substring(pos,pos1),
amorphous.substring(pos1)substring(pos,pos1),
amorphous.substring(pos1)substring(pos,pos1),
amorphous.substring(pos1) +1,pos2),
amorphous.substring(pos2+1,pos3));
pos = pos3+1;
} else { // 讀取非晶態資料庫時發生錯誤
if (pos+30 Alert('在無定形資料庫中讀取“'
+無定形.substring(pos,pos+30) + '”')時出錯;
pos = 無定形.indexOf(“*”,pos) + 1;
}
}
回傳這個;
}
var array = new Object();
array_length = 0; // Netscape 2 修正
varposition = new Object();
position_lescapeth = 0varposition = new Object();
position_length = 0008;
function pattern(str) {
array_length =position_length = 0;
while ((str.length > 1) && (str.charAt(0) == "*")) {
str = str . .length);
}
while ((str.length > 1) && (str.charAt(str.length-1) == "*")) {
str = str.substring( 0,str.length-1 );
}
if (str == "*")
return "(true)";
if (str.indexOf("*") == -1) {
array[array_length++ ] = str;
pat = "(combo.indexOf(array[0]) != -1)";
} else {
left = right = 0;
pat2 = "";
pat = "((((位置[0] =combo.indexOf (array[0])) != -1)";
while ((right = str.indexOf("*",left)) != -1) {
array[array_length++] = str.substring(左,右);
pat += " && (position["+(position_length)+"] +(++position_length)+"] =combo.indexOf(array[" +(array_length)
+"] ,position["+(position_length-1)+"]+array["+(array_length-1)+"].length"+")))";
if (!match_across_word_boundaries)
pat2 = " && (no_back_up = ((back_up_pos +=combo.substring("
+"temp_pos = back_up_pos = 位置["
+(position_length-1)+"]+array["+(array_length-1)+" ].length,position["
+ (position_length) + "]).lastIndexOf(' ')) left = right+1;
}
array[array_length++] = str.substring(left,str.length);
pat += pat2+")";
}
return pat;
}
function search(str) {
menu_length = 0;
temp = new Object();
temp_length = 0;
temp = new Object();
temp_length = 0; Object();
pos = 0;
while ((pos = str) .indexOf(" ")) != -1
&& and_search != "exact") {
words[words_length] = str.substring(0, pos);
if (words[words_length].length > 0)
Words_length++;
if (str.length == 1)
str="";
else
str = str.substring(str="";
else
str = str.substring(str. );
}
if (str.length > 0)
words [words_length++] = str;
for (q=0;qtemp_length = 0;qtemp_length = 0;
= WordsCase. );
pattern_string = pattern(str);
start_pos = back_up_pos = 0;
len = (and_search=="and"&&q>0?menu_length:database_length);
for (n=0; nfor (n=0; nfor (n=0; nno_back_up = true;
position_length = 0;
if (and_search= ="and"&&q>0) {
combo = (menu[n].title + " " + menu[n].keywords).toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase().toLowerCase);
} else {
combo = (database[n].title + " " + database[n].keywords).toLowerCase();
}
combo =combo.substring(start_pos,combo.length);
combo =combo.substring(start_pos,combo.length);
if (eval (pattern_string)) { // 找到
temp[temp_length++] = ( and_search=="and"&&q>0?menu[n]:database[n]);
start_pos = 0;
} else if (!no_back_up) { // 在新位置再嘗試模式
n--;
start_pos += back_up_pos+1;
} else { // 找不到
start_pos = 0;
}
}
if (and_search!="and" && q> 0) {
added = 0;
for (i=0; iduplicate = false;
for (j=0;jif (menu[j] == temp[i]) {
duplicate = true;
}
}
if (!duplicate)
menu[menu_length+(added++)] = temp[i];
}
menu_length + menu_length for(h=0;halert("首先必須輸入要搜尋的關鍵字。");
return false;
}
and_search = (document.entryform.and_or.selectedIndex == 0?"and":"or");
if (document.entryform.and_or.selectedIndex == 2)
and_search = "exact";
if (version >= 1.1) {
search(document.entryform.keywords. value);
if (menu_length == 0)
menu[menu_length++] = new Page("","找不到!","");
document.display.found.options.length = menu_length; =0; nif (menu[n].title.length document.display.found.options[n].text = menu[n].title;
else
document .display.found.options[n].text = menu[n].title.substring(0,50);
document.display.found.options[n].value = menu[n].url;
}
} else {
location.href = location.pathname + "?"
+ escape(document.entryform.keyword.value)
+ (and_search != "or"?"&"+and_search:"");
}
return false;
}
function go_there() {
sel = document.display.found.selectedIndex;
if ((sel != -1) && (document.display.found.options[.長度> 0))
location.href = document.display.found.options[sel].value;
}

var 無定形= document.database.list.value;

temp_str = 無定形.substring(amorphous.substring. -2,非晶.length);
if (temp_str.indexOf("*") == -1)
非晶+= "* ";
else
非晶+= " "; // 非晶體資料庫最後一個星號之後必須有Character

database_length = 0; // Netscape 2 修正

var 資料庫 = new Database(); // 從非晶體資料庫讀入

menu_length = 0; // Netscape 2 修正

var menu = new Object();

string = "";

and_search = "or";
if (location.search.length > 1) {
string = unescape(location.search.substringcation.search.substringcation.search.sub (1,location.search.length));
pos = 0;
while ((pos = string.indexOf('"',pos)) != -1) {
string = string.substring(0,pos) + '\"' + string.substring(pos+1,string.length);
pos += 2;
}
if (string.substring(string.length-4,string.length) == "&and" ) {
string = string.substring(0,string.length-4);
and_search = "and";
} else if (string.substring(string.length-6,string.length) == "&exact") {
string = string.substring(0,string.length-6);
and_search = "exact";
} else if (string.substring(string.length-3,string.length) == "&or") {
") {
string = string.substring(0,string.length-3);
and_search = "or";
}
search(string);
}
document.write('

'
+'搜尋: '
+'
+'size=1> ;

'
+'

+'value="前往那裡">
');
// -->
 

 以上就是站內搜尋腳本範例四(javascript)_Javascript教學的內容,更多相關內容請關注PHP中文網(www ) .php.cn) 


相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板