欢迎光临
我们一直在努力

站内搜索脚本例子二(JavaScript)

建站超值云服务器,限时71元/月

脚本说明:

把如下代码加入<body>区域中

<script language="javascript">

var key = "";

function makeentry (){

this.date = "";

this.name="";

this.url = "";

this.desc = "";

this.category = "";

return this;

}

function makearray(n) {

this.length = n;

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

this[k] = "";

}

return this;

}

function makelinks(size) {

this.length = size;

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

this[r] = new makeentry();

this[r].date = datesarray[r];

this[r].name = namesarray[r];

this[r].url = urlsarray[r];

this[r].desc = descarray[r];

}

return this;

}

var linksize=0

datesarray = new makearray(linksize);

namesarray = new makearray(linksize);

urlsarray = new makearray(linksize);

descarray = new makearray(linksize);

var arraycount=0

arraycount += 1

datesarray[arraycount] = "5/30/2000"

urlsarray[arraycount] = "http://www.163.net"

namesarray[arraycount] = "网易"

descarray[arraycount] = "163 netease yeah 126 chinese "

//alert(arraycount)

arraycount += 1

datesarray[arraycount] = "5/30/2000 "

urlsarray[arraycount] = "http://www.sina.com.cn"

namesarray[arraycount] = "新浪网"

descarray[arraycount] = "sina net chat chatting news super"

//alert(arraycount)

arraycount += 1

datesarray[arraycount] = "5/30/2000 "

urlsarray[arraycount] = "http://www.sohu.com"

namesarray[arraycount] = "搜狐"

descarray[arraycount] = "sohu net chat news "

//alert(arraycount)

linksize = arraycount;

// —-end data ——-

function showall(linkobj) {

for (var s=1; s<= linkobj.length; s++) {

showlink(linkobj,s);

}

}

function showlink (links, index) {

//document.write("<table border>");

document.write("<tr><td>" + links[index].date +"</td>");

document.write("<td><a href=" + links[index].url +">" + links[index].name + "</a></td>");

document.write("<td>" + links[index].desc + "</td></tr>");

//document.write("</table>");

}

function searchlinks(links, keyword){

document.write("搜寻结果: " +keyword +"<br>");

document.write("<table border>");

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

//document.write(q+".")

if (links[q].url.indexof(keyword) != -1){

// document.write("search results for keyword: "+keyword+ "<br>" +links[q].name +"<p>")

//document.write("搜寻结果: "+keyword+ "<br>" );

showlink(links,q);

continue;

}

if (links[q].desc.indexof(keyword) != -1) {

showlink(links,q);

continue;

}

if (links[q].date.indexof(keyword) != -1) {

showlink(links,q);

continue;

}

if (links[q].name.indexof(keyword) != -1) {

showlink(links,q);

continue;

}

}

document.write("</table>");

}

// final stuff

// the main program —

jsi = new makelinks(linksize);

document.write("<title>站内查询</title>");

searchlinks(jsi, prompt("输入查询关键字:","输入查询关键字:"));

document.write("<hr>");

document.write("按<b>search again</b>再次查询<hr>");

document.write("<form><input type=button onclick=history.go(0) value=search again></form>");

// show all the links

//document.write("<table border>");

//showall(jsi);

//document.write("</table>");

</script>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 站内搜索脚本例子二(JavaScript)
分享到: 更多 (0)