我是JavaScript的新手,我想将搜索结果限制为10。 www.bikinituna.com/search/ 例如,在搜索框中键入set,您将获得所有可用结果 我只希望显示最多10个结果。
这是JavaScript:
FILE JSE_FORM:
var results_location = "results.html";
function search_form(jse_Form) {
if (jse_Form.d.value.length > 0) {
document.cookie = "d=" + escape(jse_Form.d.value);
window.location = results_location;
}
}
FILE JSE_SEARCH:
var include_num = 1;
var bold = 0;
var s = new Array();
s[0] = "bikinituna.com/celebs/padmalakshmi/set1/^/celebs/padmalakshmi/set1/^Padma Lakshmi [August 1, 2013]^padma, lakshmi";
s[1] = "bikinituna.com/celebs/josieconseco/set1/^/celebs/josieconseco/set1/^Josie Conseco [August 2, 2013]^josie, conseco";
s[2] = "bikinituna.com/celebs/debbieotoole/set1/^/celebs/debbieotoole/set1/^Debbie O'Toole [August 3, 2013]^debbie, otoole";
s[3] = "bikinituna.com/celebs/rihanna/set1/^/celebs/rihanna/set1/^Rihanna [August 4, 2013]^rihanna";
s[4] = "bikinituna.com/celebs/kourtneykardashian/set1/^/celebs/kourtneykardashian/set1/^Kourtney Kardashian [August 5, 2013]^kourtney, kardashian";
s[5] = "bikinituna.com/celebs/cassieventura/set1/^/celebs/cassieventura/set1/^Cassie Ventura [August 6, 2013]^cassie, ventura";
s[6] = "bikinituna.com/celebs/jillmartin/set1/^/celebs/jillmartin/set1/^Jill Martin [August 7, 2013]^jill, martin";
s[7] = "bikinituna.com/celebs/courtneystodden/set1/^/celebs/courtneystodden/set1/^Courtney Stodden [August 8, 2013]^courtney, stodden";
s[8] = "bikinituna.com/celebs/irinashayk/set1/^/celebs/irinashayk/set1/^Irina Shayk [August 9, 2013]^irina, shayk";
s[9] = "bikinituna.com/celebs/candiceswanepoel/set1/^/celebs/candiceswanepoel/set1/^Candice Swanepoel [August 10, 2013]^candice, swanepoel";
s[10] = "bikinituna.com/celebs/evalongoria/set1/^/celebs/evalongoria/set1/^Eva Longoria [August 11, 2013]^eva, longoria";
s[11] = "bikinituna.com/celebs/oliviawilde/set1/^/celebs/oliviawilde/set1/^Olivia Wilde [August 12, 2013]^olivia, wilde";
s[12] = "bikinituna.com/celebs/kristymaclaren/set1/^/celebs/kristymaclaren/set1/^Kristy MacLaren [August 13, 2013]^kristy, maclaren";
s[13] = "bikinituna.com/celebs/doutzenkroes/set1/^/celebs/doutzenkroes/set1/^Doutzen Kroes [August 14, 2013]^doutzen, kroes";
s[14] = "bikinituna.com/celebs/gerihalliwell/set1/^/celebs/gerihalliwell/set1/^Geri Halliwell [August 15, 2013]^geri, halliwell";
s[15] = "bikinituna.com/celebs/kellybrook/set1/^/celebs/kellybrook/set1/^Kelly Brook [August 16, 2013]^kelly, brook";
s[16] = "bikinituna.com/celebs/dianavickers/set1/^/celebs/dianavickers/set1/^Diana Vickers [August 17, 2013]^diana, vickers";
s[17] = "bikinituna.com/celebs/bethennyfrankel/set1/^/celebs/bethennyfrankel/set1/^Bethenny Frankel [August 18, 2013]^bethenny, frankel";
s[18] = "bikinituna.com/celebs/jennifernicolelee/set1/^/celebs/jennifernicolelee/set1/^Jennifer Nicole Lee [August 19, 2013]^jennifer, nicole, lee";
s[19] = "bikinituna.com/celebs/lolaponce/set1/^/celebs/lolaponce/set1/^Lola Ponce [August 20, 2013]^lola, ponce";
s[20] = "bikinituna.com/celebs/gabriellereece/set1/^/celebs/gabriellereece/set1/^Gabrielle Reece [August 21, 2013]^gabrielle, reece";
s[21] = "bikinituna.com/celebs/claudiaromani/set1/^/celebs/claudiaromani/set1/^Claudia Romani [August 22, 2013]^claudia, romani";
s[22] = "bikinituna.com/celebs/suzannequast/set1/^/celebs/suzannequast/set1/^Suzanne Quast [August 23, 2013]^suzanne, quast";
s[23] = "bikinituna.com/celebs/mileycyrus/set1/^/celebs/mileycyrus/set1/^Miley Cyrus [August 24, 2013]^miley, cyrus";
s[24] = "bikinituna.com/celebs/charismacarpenter/set1/^/celebs/charismacarpenter/set1/^Charisma Carpenter [August 25, 2013]^charisma, carpenter";
s[25] = "bikinituna.com/celebs/ilaryblasi/set1/^/celebs/ilaryblasi/set1/^Ilary Blasi [August 26, 2013]^ilary, blasi";
s[26] = "bikinituna.com/celebs/alessandraambrosio/set1/^/celebs/alessandraambrosio/set1/^Alessandra Ambrosio [August 27, 2013]^alessandra, ambrosio";
s[27] = "bikinituna.com/celebs/anaiszanotti/set1/^/celebs/anaiszanotti/set1/^Anais Zanotti [August 28, 2013]^anais, zanotti";
s[28] = "bikinituna.com/celebs/lindsaylohan/set1/^/celebs/lindsaylohan/set1/^Lindsay Lohan [August 29, 2013]^lindsay, lohan";
s[29] = "bikinituna.com/celebs/carmenortega/set1/^/celebs/carmenortega/set1/^Carmen Ortega [August 30, 2013]^carmen, ortega";
s[30] = "bikinituna.com/celebs/emmanuellechriqui/set1/^/celebs/emmanuellechriqui/set1/^Emmanuelle Chriqui [August 31, 2013]^emmanuelle, chriqui";
s[31] = "bikinituna.com/celebs/vanessahudgens/set1/^/celebs/vanessahudgens/set1/^Vanessa Hudgens [August 2013 Bonus]^vanessa, hudgens";
var cookies = document.cookie;
var p = cookies.indexOf("d=");
if (p != -1) {
var st = p + 2;
var en = cookies.indexOf(";", st);
if (en == -1) {
en = cookies.length;
}
var d = cookies.substring(st, en);
d = unescape(d);
}
var od = d;
var m = 0;
if (d.charAt(0) == '"' && d.charAt(d.length - 1) == '"') {
m = 1;
}
var r = new Array();
var co = 0;
if (m == 0) {
var woin = new Array();
var w = d.split(" ");
for (var a = 0; a < w.length; a++) {
woin[a] = 0;
if (w[a].charAt(0) == '-') {
woin[a] = 1;
}
}
for (var a = 0; a < w.length; a++) {
w[a] = w[a].replace(/^\-|^\+/gi, "");
}
a = 0;
for (var c = 0; c < s.length; c++) {
pa = 0;
nh = 0;
for (var i = 0; i < woin.length; i++) {
if (woin[i] == 0) {
nh++;
var pat = new RegExp(w[i], "i");
var rn = s[c].search(pat);
if (rn >= 0) {
pa++;
} else {
pa = 0;
}
}
if (woin[i] == 1) {
var pat = new RegExp(w[i], "i");
var rn = s[c].search(pat);
if (rn >= 0) {
pa = 0;
}
}
}
if (pa == nh) {
r[a] = s[c];
a++;
}
}
co = a;
}
if (m == 1) {
d = d.replace(/"/gi, "");
var a = 0;
var pat = new RegExp(d, "i");
for (var c = 0; c < s.length; c++) {
var rn = s[c].search(pat);
if (rn >= 0) {
r[a] = s[c];
a++;
}
}
co = a;
}
function return_query() {
document.jse_Form.d.value = od;
}
function num_jse() {
document.write(co);
}
function out_jse() {
if (co == 0) {
document.write('Your search did not match any models.', '<br><br>');
return;
}
for (var a = 0; a < r.length; a++) {
var os = r[a].split("^");
if (bold == 1 && m == 1) {
var br = "<b>" + d + "</b>";
os[2] = os[2].replace(pat, br);
}
if (include_num == 1) {
document.write(os[2], '<br>', '<a href="', os[1], '">', os[0], '</a><br><br>');
} else {
document.write('<a href="', os[1], '">', os[0], '</a><br>', os[2]);
}
}
}
答案 0 :(得分:1)
您只需要限制循环,替换每个
r.length
与
Math.min(r.length,10)