2006-01-23 01:34Zoom全屏很酷的JS搜索引擎

很酷的JS搜索引擎

1.在需要放搜索引擎页(如:js-ss1.htm)的<body>与</body>中间加入下面代码:

<script language="javascript">
<!--
var search_htm_url = "js-ss1-1.htm";

function searchPage() {
if ((document.searchpage.keyword.value.length == 0)
|| (document.searchpage.keyword.value == " ")) {
alert("请填入关键字!");
} else {
sel = document.searchpage.and_or.selectedIndex;
location.href = search_htm_url + "?"
+ escape(document.searchpage.keyword.value)
+ (sel==0?"&and":(sel==2?"&exact":"&or"));
}
return false;
}

document.write('<form name="searchpage" onSubmit="return searchPage()">'
+'站内搜索: <input type="text" size=22 name="keyword"> '
+'<input type="button" value="搜索" onClick="searchPage()" style="background-color: #9999FF; color: #FFFFFF"><br>'
+'<select name="and_or" size=1><option>全部(AND)<option>关联 '
+'(OR)<option>精确</select></form>');
// -->
</script>

2.新建一数据库页(如:js-ss1-1.htm)将下面代码放到<body>与</body>中间:

<form NAME="database">                                                
<input type="hidden" name="list"                                                
value="2000web.htm~《2000网》是企业建站、电子商务首选站点!|企业建站 软件编程 客户服务 企业登录 信息发布 相关政策 友情链接 首页^企业建站、电子商务首选站点!为企业建站提供全方位的服务!*qyjz.htm~企业建站、域名查询|企业建站 域名查询 中文域名查询 中、英文域名查询 英文域名查询 域名检索 中、英文域名检索 中文域名检索 英文域名检索 域名注册 域名申请 虚拟主机 网页制作 建站套装 诚征代理 建站步骤^为企业建站提供建站从域名申请、租用主机和网页设计制作一条龙服务!*ymzc.htm~域名注册、域名申请|域名注册 域名申请 中、英文域名注册 中文域名注册 英文域名注册 国际域名 国内域名 中文国际域名 中文通用域名 注册类型 注册价格 组成规则 申请条件 提交申请表 注册完成时间 汇款地址 联系电话、传真^域名注册、申请提供中、英文域名注册。从价格、申请条件、完成注册时间都有详尽的说明。                                                
*xnzj.htm~租用虚拟主机服务、租用申请订单|租用虚拟主机 租用申请订单 主机存放地点 主机接入速度 主机空间 邮箱数量 主机租用价格 主机技术支持 ^虚拟主机租用从价格、空间大小、地点和各项技术指标以及租用订单申请都做详细的说明。*wyzz.htm~网页设计制作和其它单项价格|网页设计制作 主页制作 企业CI形象设计范例 企业策划 标志设计范例 网页设计范例 网站策划 标志设计 首页Homepage设计 普通页面设计 产品图片处理 汉英互译 视频音频转换 留言簿 反馈单 Gif动画制作 Java Flash 聊天室 WEB-BBS论坛 网上购物 其它软件编程 单项价格 各项制作报价 制作订单^网页设计制作和其它各单项的服务报价以及制作订单。*jztz.htm~建站套装-为您企业量身订作!|建站套装 快速建站 经济网站 普通网站 中等网站 高级网站 建站套装价格 建站套装订单^建站套装可根据您的公司的实际需求,为您提供量身订做高品质的网站。  
您无须花时间、无须花高薪聘请专业网站管理维护人员。《2000网》都可以替您操办。*czdl.htm~诚征业务代理|诚征业务代理 代理条件要求 代理合同 代理价格 代理申请表^欢迎您加入我们的行列,成为我们的业务代理。圆你一人公司的“老板梦”。*kffw.htm~客户服务 建站问题解答!|域名解答 用户FAQ 网站推广 电子商务 如何在线注册域名? 如何租用虚拟主机? 如何填网页委托制作订单? 如何量身订做“建站套装”? 如何上网找买家? 企业库存积压产品如何上网清仓?^为您提供建站和上网帮助的栏目。*ymjd.htm~域名解答 虚拟主机问答|什么是域名? 域名的类型? 域名命名及组成? 注册域名的规则是什么? 网站名称注册管理暂行办法 网站名称注册管理暂行办法实施细则 中华人民共和国计算机信息系统安全保护条例 什么是虚拟主机?虚拟主机如何选择? 什么是独立的CGI-BIN目录? 如何用CuteFTP上传文件?  
 什么是匿名FTP?什么是FTP断点续传? Linex主机和NT主机如何设定(FAQ)? 管理一个虚拟主机是否很容易?^详细的域名、虚拟主机知识解答。*faq.htm~用户FAQ|LINUX用户区 NT用户区 文件上载 修改密码 计数器 访客留言簿 BBS讨论区 简易数据库 增强型电子邮箱 口令保护网页的设置 Cgi-Email FormMail^虚拟主机设置及有关的详细操作步骤。*wztg.htm~网站推广 服务报价|网站策划 登录搜索引擎 网站推广 网站维护、管理 广告链接 广告信函 服务价格^通过网站的策划与推广配合精美的网页设计和定时的网页更新,这样企业才能吸引和留住更多用户,提高您企业的形象和知名度。*rjbc.htm~软件编程 专业的软件制作|软件制作 网络应用 软件设计 网络编程 网络设计^我们拥有一个专业的软件制作编程小组专门为客户提供各项的软件编程和网络应用的设计和制作。*qydl.htm~企业登录|登录网站^将您的企业网站登录到本站上,让别人更容易找到您。  
 *guestbook.htm~信息发布|发布信息 发布您企业供求信息^为您企业供求信息发布,提高您企业的知名度。*xgzc.htm~相关政策 了解国家政策、法规|介绍《个人独资企业法》 《个人独资企业登记管理办法》 网站名称注册管理暂行办法 网站名称注册管理暂行办法实施细则 中华人民共和国计算机信息系统安全保护条例 域名,你是知识产权吗?^深入了解和体会国家的政策、法规,为您企业发展提供正确的方向*wysj1.htm~ 由本站设计制作的网站范例|网页设计范例 Homepage设计 普通页面设计 网页设计制作 主页制作^可为您的网站设计制作提供参考。*">                                                
</form> \\按照上述格式修改成为你自己的数据库文件                                               

<script language="javascript">                                                
<!--                                                
function Page(url,title,keywords,description) {                                                
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;                                                
this.description = description;                                                
return this;                                                
}                                                
function Database() {                                                
var pos = 0;                                                
while ((pos1 = amorphous.indexOf("~",pos)) != -1) {                                                
pos2 = amorphous.indexOf("|",pos1+1);                                                
pos3 = amorphous.indexOf("^",pos2+1);                                                
pos4 = amorphous.indexOf("*",pos3+1);                                                
if ((pos2 != -1)                                                
&& (pos2 < pos3) && (pos3 < pos4)                                                
&& (pos4 <= amorphous.indexOf("*",pos))) {                                                
this[database_length++] = new Page(amorphous.substring(pos,pos1),                                                
amorphous.substring(pos1+1,pos2),                                                
amorphous.substring(pos2+1,pos3),                                                
amorphous.substring(pos3+1,pos4));                                                
pos = pos4+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;                                                
}                                                
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[words_length] = str.substring(0,pos);                                                
if (words[words_length].length > 0)                                                
words_length++;                                                
if (str.length == 1)                                                
str="";                                                
else                                                
str = str.substring(pos+1,str.length);                                                
}                                                
if (str.length > 0)                                                
words[words_length++] = str;                                                
for (q=0;q<words_length;q++) {                                                
temp_length = 0;                                                
str = words[q].toLowerCase();                                                
len = (and_search=="and"&&q>0?menu_length:database_length);                                                
for (n=0; n<len; n++) {                                                
if (and_search=="and"&&q>0) {                                                
combo = (menu[n].title + " " + menu[n].description                                                
+ " " + menu[n].keywords).toLowerCase();                                                
} else {                                                
combo = (database[n].title + " " + database[n].description                                                
+ " " + database[n].keywords).toLowerCase();                                                
}                                                
if (combo.indexOf(str) != -1) // found                                                
temp[temp_length++] = (and_search=="and"&&q>0?menu[n]:database[n]);                                                
}                                                
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[j] == temp[i]) {                                                
duplicate = true;                                                
}                                                
}                                                
if (!duplicate)                                                
menu[menu_length+(added++)] = temp[i];                                                
}                                                
menu_length += added;                                                
} else {                                                
for(h=0;h<temp_length;h++)                                                
menu[h] = temp[h];                                                
menu_length = temp_length;                                                
}                                                
}                                                
}                                                
function entry() {                                                
if ((document.entryform.keyword.value.length == 0)                                                
|| (document.entryform.keyword.value == " ")) {                                                
alert("你必须填写关键字!");                                                
return false;                                                
}                                                
and_search = (document.entryform.and_or.selectedIndex == 0?"and":"or");                                                
if (document.entryform.and_or.selectedIndex == 2)                                                
and_search = "exact";                                                
location.href = location.pathname + "?"                                                
+ escape(document.entryform.keyword.value)                                                
+ (and_search != "or"?"&"+and_search:"");                                                
return false;                                                
}                                                
function redWord(str) {                                                
for(r=0; r<words_length; r++) {                                                
pos = -3;                                                
word = words[r].toLowerCase();                                                
while ((pos = str.toLowerCase().indexOf(word,pos+3)) != -1) {                                                
val = pos+word.length;                                                
str = str.substring(0,pos) + "*"                                                
+ str.substring(pos,val) + "|"                                                
+ str.substring(val,str.length);                                                
}                                                
}                                                
pos = -16;                                                
while ((pos = str.toLowerCase().indexOf("*",pos+16)) != -1)                                                
str = str.substring(0,pos) + "<font color=red>"                                                
+ str.substring(pos+1,str.length);                                                
pos = -7;                                                
while ((pos = str.toLowerCase().indexOf("|",pos+7)) != -1)                                                
str = str.substring(0,pos) + "</font>"                                                
+ str.substring(pos+1,str.length);                                                
return str;                                                
}                                                
                                                
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";                                                
} else if (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" onSubmit="return entry()">'                                                
+'关键字:<input type="text" size=22 '                                                
+'name="keyword" value="'+string+'"> '                                                
+'<input type="button" value="搜索" onClick="entry()" style="background-color: #9999FF; color: #FFFFFF"><br><select name="and_or" '                                                
+'size=1><option'+(and_search=="and"?" selected":"")+'>全部 '                                                
+'(AND)<option'+(and_search=="or"?" selected":"")+'>关联 '                                                
+'(OR)<option'+(and_search=="exact"?" selected":"")+'>精确 '                                                
+'word</select></form><br>');                                                
if (location.search.length > 1)                                                
document.write('查询结果:<br><br>\n');                                                
                                                
for (n=0; n<menu_length; n++)                                                
document.write('<a href="'+menu[n].url+'">'+menu[n].title                                                
+'</a><br>'+redWord(menu[n].description)+'<br>Keywords: '                                                
+redWord(menu[n].keywords)+'<br><br>\n');                                                
if ((menu_length == 0) && (location.search.length > 1))                                                
document.write('对不起:你查询的关键字"'+string+'"没有发现!\n');                                                
// -->                                                
</script>

说明:按照上述格式修改成为你自己的数据库文件;将文字、链接换成您需要的即可。

作者:Poster:csnetwork 分类:Category:网页设计与制作讨论 回复Comments:  引用Trackback:  阅读Read: 

回复Comments

{commenttime}{commentauthor}

{CommentUrl}
{commentcontent}
留言回复(带*号为必填)Post Comment(* must be)

作 者Author:

 主 页Homepage:

 邮 箱Email:

内 容Content:

 选 项option:使用表情Enable Smile转换UBBEnable UBB记住我Remember me

 验证码Verify Code:验证码