Cheer 发表于 2007-4-28 10:54:24

测试搜索这个脚本将查询的结果显示在了文本框中

把下列代码加到网页的<body></body>标签之间 从google下载我的照片管理软件
要完成此效果把如下代码加入到<body>区域中

<form name="database">

<input type="hidden" name="list" value='http://www.webcrawler.com~webcrawler|keywords for first

file go here separated by spaces^a great search engine from the makers of

aol!*http://typhoon.500.to~javascript fairyland|java javascript search html download cgi perl

dhtml games activex 下载 脚本^typhoon start!*http://www.1.com/~1.com|activex asp c/c++ cgi

databases java javascript^1.com!*'>

</form>

<p>

<script language="javascript">

<!--

version = 1.0;

// -->

</script>

<script language="javascript1.1">

<!--

version = 1.1;

// -->

</script>

<script language="javascript">

<!--

// when set to true, searching for "fun*y" matches in the string "fun sky".

//(it will also match the string "fun and here is some long dummy text for you"

//which is obviously not what they were looking for, so we suggest you set

//match_across_word_boundaries to false)

// when set to false, the * operator will not match across word boundaries so

// the above example will not match.

match_across_word_boundaries = false; // false is suggested strongly





// ************ no need to modify anything below this point ************



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);

}

this.title = title;

this.keywords = keywords;

return this;

}

function database() {

var pos = 0;

while ((pos1 = amorphous.indexof("~",pos)) != -1) {

pos2 = amorphous.indexof("|",pos1+1);

pos3 = amorphous.indexof("*",pos2+1);

if ((pos2 != -1)

&& (pos2 < pos3) && (pos3 <= amorphous.indexof("*",pos))) {

   this = new page(amorphous.substring(pos,pos1),

   amorphous.substring(pos1+1,pos2),

   amorphous.substring(pos2+1,pos3));

   pos = pos3+1;

} else { // error reading amorphous database

   if (pos+30 <= amorphous.length)

    alert('error reading in amorphous database around "'

   + amorphous.substring(pos,pos+30) + '"');

   pos = amorphous.indexof("*",pos) + 1;

}

}

return this;

}

var array = new object();

array_length = 0; // netscape 2 fix

var position = new object();

position_length = 0; // netscape 2 fix

function pattern(str) {

array_length = position_length = 0;

while ((str.length > 1) && (str.charat(0) == "*")) {

str = str.substring(1,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 = str;

pat = "(combo.indexof(array) != -1)";

} else {

left = right = 0;

pat2 = "";

pat = "(((position = combo.indexof(array)) != -1)";

while ((right = str.indexof("*",left)) != -1) {

   array = str.substring(left,right);

   pat += " && (position["+(position_length)+"] < (position["

    +(++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["

   +(position_length-1)+"]+array["+(array_length-1)+"].length,position["

   + (position_length) + "]).lastindexof(' ')) < temp_pos))" + pat2;

   left = right+1;

}

array = str.substring(left,str.length);

pat += pat2+")";

}

return pat;

}

function search(str) {

menu_length = 0;

temp = new object();

temp_length = 0;

words_length = 0;

words = new object();

pos = 0;

while ((pos = str.indexof(" ")) != -1

&& and_search != "exact") {

words = str.substring(0,pos);

if (words.length > 0)

   words_length++;

if (str.length == 1)

   str="";

else

   str = str.substring(pos+1,str.length);

}

if (str.length > 0)

words = str;

for (q=0;q<words_length;q++) {

temp_length = 0;

str = words.tolowercase();

pattern_string = pattern(str);

start_pos = back_up_pos = 0;

len = (and_search=="and"&&q>0?menu_length:database_length);

for (n=0; n<len; n++) {

   no_back_up = true;

   position_length = 0;

   if (and_search=="and"&&q>0) {

    combo = (menu.title + " " + menu.keywords).tolowercase();

   } else {

    combo = (database.title + " " + database.keywords).tolowercase();

   }

   combo = combo.substring(start_pos,combo.length);

   if (eval(pattern_string)) { // found

    temp = (and_search=="and"&&q>0?menu:database);

    start_pos = 0;

   } else if (!no_back_up) { // try pattern again in new spot

    n--;

    start_pos += back_up_pos+1;

   } else { // not found

    start_pos = 0;

   }

}

if (and_search!="and" && q>0) {

   added = 0;

   for (i=0;i<temp_length;i++) {

    duplicate = false;

    for (j=0;j<menu_length&&!duplicate;j++) {

   if (menu == temp) {

      duplicate = true;

   }

    }

    if (!duplicate)

   menu = temp;

   }

   menu_length += added;

} else {

   for(h=0;h<temp_length;h++)

    menu = temp;

   menu_length = temp_length;

}

}

}

function entry() {

if ((document.entryform.keyword.value.length == 0)

|| (document.entryform.keyword.value == " ")) {

alert("first you must enter a keyword to search for.");

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.keyword.value);

if (menu_length == 0)

   menu = new page("","not found!","");

document.display.found.options.length = menu_length;

for (n=0; n<menu_length; n++) {

   if (menu.title.length <= 50)

    document.display.found.options.text = menu.title;

   else

    document.display.found.options.text = menu.title.substring(0,50);

   document.display.found.options.value = menu.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.value.length > 0))

location.href = document.display.found.options.value;

}



var amorphous = document.database.list.value;

temp_str = amorphous.substring(amorphous.length-2,amorphous.length);

if (temp_str.indexof("*") == -1)

amorphous += "* ";

else

amorphous += " "; // amorphous database must have characters after last asterisk



database_length = 0; // netscape 2 fix

var database = new database(); // read in from amorphous database



menu_length = 0; // netscape 2 fix

var menu = new object();



string = "";

and_search = "or";

if (location.search.length > 1) {

string = unescape(location.search.substring(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";

} elseif (string.substring(string.length-3,string.length) == "&or") {

string = string.substring(0,string.length-3);

and_search = "or";

}

search(string);

}

document.write('<form name="entryform" class="pt9" onsubmit="return entry()">'

+'search for: <input type="text" type="pt9" size=15 name="keyword" value="'+string+'"> '

+'<input type="button" class="pt9" value="search" onclick="entry()"><br><select name="and_or" '

+'size=1><option'+(and_search=="and"?" selected":"")+'>and查询 '

+'(and)<option'+(and_search=="or"?" selected":"")+'>or查询 '

+'(or)<option'+(and_search=="exact"?" selected":"")+'>完全'

+'匹配</select><br>""可以使用通配符</form><br>'

+'<form name="display"><select name="found" size=5>\n');

for (n=0; n<menu_length; n++)

document.write('<option value="'+menu.url+'">'+menu.title+'\n');

if ((menu_length == 0) && (location.search.length <= 1))

document.write('<option value="" class="pt9">enter a search keyword above\n');

else if ((menu_length == 0) && (location.search.length > 1))

document.write('<option value="">关键字"'

+location.search.substring(1,location.search.length)+'"没有发现!\n');

document.write('</select><br><input type="button" class="pt9" onclick="go_there()" '

+'value=" go there "></form>');

// -->

</script>
页: [1]
查看完整版本: 测试搜索这个脚本将查询的结果显示在了文本框中