Cheer 发表于 2007-4-28 10:53:12

>>>测试搜索>>>较为简单的搜索器

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

<script language="javascript">

      var key = "";

      function makeentry (){

                this.name="";

                this.url = "";

                this.desc = "";

                this.category = "";

                this.target = "";

                return this;

      }



function makearray(n) {

                this.length = n;

                for (var k = 1; k <= n; k++) {

                              this = "";

                }

                return this;

      }               



      function makelinks(size) {

                              this.length = size;

                              for (var r=1; r<= size; r++) {

                                                      this = new makeentry();

                                                      this.name = namesarray;

                                                      this.url = urlsarray;

                                                      this.desc = descarray;

                                                      this.category = categoryarray;

                                                      this.target = targetarray;

                                                      }

                                        return this;

                        }





var linksize=0



datesarray = new makearray(linksize);

namesarray = new makearray(linksize);

urlsarray = new makearray(linksize);

descarray = new makearray(linksize);

categoryarray = new makearray(linksize);

targetarray = new makearray(linksize);





var arraycount=0



<!-- 数据库部分由此开始 -->

arraycount += 1

urlsarray = "http://typhoon.500.to"

namesarray = "javascript fairyland"

descarray = "java, javascript, scripts, applet, html, dhtml ,activex, midi, search,

downloads, 脚本, free, 免费资源"

categoryarray = "大量详细的javascript源代码和实例说明!"

targetarray = "target=_blank"



arraycount += 1

urlsarray = "http://members.aol.com/master54x/anime.html"

namesarray = "anime master"

descarray = "anime master, anime, project a-ko, vampire hunter d, tenchi muyo,

bubblegum crisis, sailor moon, sailormoon, gunsmith cats, slayers, all purpose cultural cat girl

nuku nuku, plastic little, devil hunter yohko, iria:zeiram the animation, iria, ranma 1/2,

ranma, fist of the north star, multimedia, galleries, pic galleries, picture gallery, image

gallery, image galleries"

categoryarray = "multimedia, image galleries for project a-ko, vampire hunter d,

tenchi muyo, bubblegum crisis, sailormoon, gunsmith cats, slayers, all purpose cultural cat girl

nuku nuku, plastic little, devil hunter yohko, iria:zeiram the animation, ranma 1/2, and fist

of the north star."

targetarray = "target=_blank"



arraycount += 1

urlsarray = "http://www.geocities.com/tokyo/towers/6508/"

namesarray = "the anime shrine"

descarray = "the anime shrine, anime shrine, anime, the anime shrine, anime shrine,

manga, saintseiya, fushigiyuugi, fushigi yuugi, evangelion, neon genesis evangelion, eva, ranma,

ranma 1/2"

categoryarray = "this is a fairly large site with large image galleries from many dif

animes, many links, gives out awards, has 3 voting shrines, also sub-shrines for fushigi yuugi,

saintseiya, evangelion, and ranma 1/2. and much more! must see!"

targetarray = "target=_blank"



arraycount += 1

urlsarray = "http://home.taegu.net/~virus/"

namesarray = "evangelion site"

descarray = "evangelion site, anime, evangelion, neon genesis, neon genesis

evangelion, eva, neon, genesis"

categoryarray = "this site is about evangelion, but available in korean only..."

targetarray = "target=_blank"



arraycount += 1

urlsarray = "http://animeonline.org/"

namesarray = "the animeonline network"

descarray = "the animeonline network, anime, animecca, news, information, anime

magazine, magazine, zine, e-zine"

categoryarray = "your online anime magazine!"

targetarray = "target=_blank"



arraycount += 1

urlsarray = "http://www.visi.com/~vdgaijin/gaijin.html"

namesarray = "psychommu gaijin anime e-zine"

descarray = "psychommu gaijin anime e-zine, anime, music, links, news, information,

e-zine, zine"

categoryarray = "our aim is to provide you with news and information on some of the

coolest aspects of anime. old and new! so come on in and enjoy!"

targetarray = "target=_blank"



arraycount += 1

urlsarray = "http://the.animearchive.org/"

namesarray = "ultimate animanga archive"

descarray = "ultimate animanga archive, anime, manga, images, pictures, image

gallery, midi, image galleries, music, chat, information, descriptions, info"

categoryarray = "searchable page of images, info, and descriptions of anime oavs and

series."

targetarray = "target=_blank"



arraycount += 1

urlsarray = "http://otakuworld.com/"

namesarray = "otaku world"

descarray = "otaku world, anime, manga, desktop themes, anime themes, search engine,

link database, web rings, web ring"

categoryarray = "one of the largest multimedia anime sources on the web!"

targetarray = "target=_blank"



arraycount += 1

urlsarray = "http://www.usagi.com"

namesarray = "usagi.com"

descarray = "usagi.com, anime, manga, links, link, database, tenchi, tenchi muyo,

download, multimedia"

categoryarray = "your guide to the online anime community!"

targetarray = "target=_blank"



arraycount += 1

urlsarray = "http://www.si.hhs.nl/~v962343/home.html"

namesarray = "richie's place"

descarray = "richie's place, anime, manga, pictures, pics, movies, links, gif

animations, animation, hentai, java, link"

categoryarray = "richie's place! over 30 pages! with a picture gallery, movies, gif

animations, games, java and more."

targetarray = "target=_blank"



linksize = arraycount;



// ----数据库结束 ------

// ----以下是输出结果检索结果的页面代码 ----



function searchlinks(links, keyword){

      document.write("<body fontsize='2' bgcolor='#000000' text='#ffffff' link='#ccffcc'

vlink='#ffffff'>")

      document.write("搜索关键字结果: <strong>" +keyword +"</strong><br><br>");

      for (var q=1; q<=links.length; q++) {



      if (links.url.tolowercase().indexof(keyword) != -1){

          document.write("<a href=" + links.url +" " + links.target + ">" + links.name +

"</a> - ");

         

          document.write( links.category + "<br><br>");

          continue;

         }

      if (links.desc.tolowercase().indexof(keyword) != -1) {

          document.write("<a href=" + links.url +" " + links.target + ">" + links.name +

"</a> - ");

         

          document.write( links.category + "<br><br>");

          continue;

         }

      if (links.name.tolowercase().indexof(keyword) != -1) {

          document.write("<a href=" + links.url +" " + links.target + ">" + links.name +

"</a> - ");

         

          document.write( links.category + "<br><br>");

          continue;

         }



   }                                       





}



</script>

<font size="5" color="#ff0000">站内搜索引擎<br>

</font><font color="#ff0000"> <font color="#000000">测试:输入关键字"java"

或中文字符"免费" 查询。</font></font> </div>

<p align=center>

<form name="form">

<div align="center">

    <p>查询关键字:

      <input type="text" size=20 name="search">

      <input type="button" name="submit" value="开始查询" onclick="validate_form()" class="pt9">

      <input type="reset" name="reset" value="清除" class="pt9">

      <br>

    </p>

   

</div>

</form>

<!-- 以下是合法性检测 -->

<script>

function validate_form() {



txt = document.form.search.value;

if (txt.indexof(".") != -1){

      alert("search is invalid! contains a '.'"); return;}

if (txt.indexof(",") != -1){

      alert("search is invalid! contains a ','"); return;}

if (txt.indexof("@") != -1){

      alert("search is invalid! contains a '@''"); return;}

if (txt.indexof("!") != -1){

      alert("search is invalid! contains a '!''"); return;}

if (txt.indexof("#") != -1){

      alert("search is invalid! contains a '#''"); return;}

if (txt.indexof("$") != -1){

      alert("search is invalid! contains a '$''"); return;}

if (txt.indexof("%") != -1){

      alert("search is invalid! contains a '%''"); return;}

if (txt.indexof("^") != -1){

      alert("search is invalid! contains a '^''"); return;}

if (txt.indexof("&") != -1){

      alert("search is invalid! contains a '&''"); return;}

if (txt.indexof("*") != -1){

      alert("search is invalid! contains a '*''"); return;}

if (txt.indexof("(") != -1){

      alert("search is invalid! contains a '(''"); return;}

if (txt.indexof(")") != -1){

      alert("search is invalid! contains a ')''"); return;}

if (txt.indexof("[") != -1){

      alert("search is invalid! contains a '[''"); return;}

if (txt.indexof("]") != -1){

      alert("search is invalid! contains a ']''"); return;}

if (txt.indexof(";") != -1){

      alert("search is invalid! contains a ';''"); return;}

if (txt.indexof(":") != -1){

      alert("search is invalid! contains a ':''"); return;}

if (txt.indexof("<") != -1){

      alert("search is invalid! contains a '<''"); return;}

if (txt.indexof(">") != -1){

      alert("search is invalid! contains a '>''"); return;}

if (txt.indexof("?") != -1){

      alert("search is invalid! contains a '?''"); return;}

if (txt.indexof("-") != -1){

      alert("search is invalid! contains a '-''"); return;}

if (txt.indexof("=") != -1){

      alert("search is invalid! contains a '=''"); return;}

if (txt.indexof("+") != -1){

      alert("search is invalid! contains a '+''"); return;}

else {

      jsi = new makelinks(linksize);

      searchlinks(jsi, txt);

document.write("<hr>");

document.write("<a href='3.htm'>返回检索页</a><br><br> ");

//将searchabledb2.htm替换为检索页的url,以便访问者返回检索页。

}



}

</script>
页: [1]
查看完整版本: >>>测试搜索>>>较为简单的搜索器