脚本说明:把如下代码加入区域中 <br>var key = "";</p> <p><br></p> <p>function makeEntry (){<br>this.Date = "";<br>this.Name="";<br>this.URL = "";<br>this.Desc = "";<br>this.Category = "";<br>return this;<br>}</p> <p>function makeArray(n) {<br>this.length = n;<br>for (var k = 1; k <= n; k++) {<br/>this[k] = "";<br/>}<br/>return this;<br/>}</p><p>function makeLinks(size) {<br/>this.length = size;<br/>for (var r=1; r<= size; r++) {<br/>this[r] = new makeEntry();<br/>this[r].Date = datesArray[r];<br/>this[r].Name = namesArray[r];<br/>this[r].URL = urlsArray[r];<br/>this[r].Desc = descArray[r];<br/>}<br/>return this;<br/>}</p><p><br/>var linksize=0</p><p>datesArray = new makeArray(linksize);<br/>namesArray = new makeArray(linksize);<br/>urlsArray = new makeArray(linksize);<br/>descArray = new makeArray(linksize);</p><p><br/>var arraycount=0</p><p><br/>arraycount += 1 <br/>datesArray[arraycount] = "5/30/2000"<br/>urlsArray[arraycount] = "http://www.163.net"<br/>namesArray[arraycount] = "网易"<br/>descArray[arraycount] = "163 netease yeah 126 chinese "<br/>//alert(arraycount)</p><p>arraycount += 1 <br/>datesArray[arraycount] = "5/30/2000 "<br/>urlsArray[arraycount] = "http://www.sina.com.cn"<br/>namesArray[arraycount] = "新浪网"<br/>descArray[arraycount] = "sina net chat chatting news super"<br/>//alert(arraycount)</p><p>arraycount += 1 <br/>datesArray[arraycount] = "5/30/2000 "<br/>urlsArray[arraycount] = "http://www.sohu.com"<br/>namesArray[arraycount] = "搜狐"<br/>descArray[arraycount] = "sohu net chat news "<br/>//alert(arraycount)</p><p>linksize = arraycount;</p><p>// ----end data -------</p><p>function showAll(linkobj) {<br/>for (var s=1; s<= linkobj.length; s++) {<br/>showLink(linkobj,s);<br/>}<br/>}</p><p>function showLink (links, index) {<br/>//document.write("<table border>");<br>document.write("<tr><td>" + links[index].Date +"</td>");<br>document.write("<td><a href="http://www.php1.cn/">document.write("<td>" + links[index].Desc + "</td></tr>");<br>//document.write("</table>");<br>}</p> <p>function searchLinks(links, keyword){<br>document.write("搜寻结果: " +keyword +"<br>");</p> <p>document.write("<table border>");<br>for (var q=1; q<=links.length; q++) {<br>//document.write(q+".")<br>if (links[q].URL.indexOf(keyword) != -1){<br>// document.write("Search Results for keyword: "+keyword+ "<br>" +links[q].Name +"<p>")<br>//document.write("搜寻结果: "+keyword+ "<br>" );<br>showLink(links,q);<br>continue;<br>}<br>if (links[q].Desc.indexOf(keyword) != -1) {<br>showLink(links,q);<br>continue;<br>}<br>if (links[q].Date.indexOf(keyword) != -1) {<br>showLink(links,q);<br>continue;<br>}<br>if (links[q].Name.indexOf(keyword) != -1) {<br>showLink(links,q);<br>continue;<br>}<br>}<br>document.write("</table>");<br>}</p> <p><br>// final stuff<br>// the main program ---</p> <p>jsi = new makeLinks(linksize);<br>document.write("<title>站内查询</title>");<br>searchLinks(jsi, prompt("输入查询关键字:","输入查询关键字:"));<br>document.write("<hr>");<br>document.write("按<b>search again</b>再次查询<hr>");<br>document.write("<form><input type=button onClick='history.go(0)' value='Search Again'></form>");</p> <p>// show all the links<br>//document.write("<table border>");<br>//showAll(jsi);<br>//document.write("</table>");</p> <p> 以上就是站内搜索脚本例子二(javascript)_Javascript教程的内容,更多相关内容请关注PHP中文网(www.php.cn)!