请参阅以下页面进行现场演示:现场演示
如果从专业中选择“麻醉学”并单击“搜索”,则除计数外一切正常。我正在寻找行数。像这样的东西:
1
2
3
4
5
6
7
但我得到的是:
1
1
1
1
1
1
1
我有两个变量,CNT 和 CNT2,我使用 CNT++ 和 CNT2++ 来增加,但它不起作用。
for (test = 0; test <= phyList.length - 1; test++) {
i = phyList[test].specialty; //get all specialty in the array
var cnt = 1;
var cnt2 = 1;
for (var iVar = 0; iVar < i.length; iVar++) {
if (i[iVar] == dSpecialtyVal) { //$(".dSpecialty").find('option:selected').attr('id')) { //if what's in the phyList array matches selection
recs += "<tr><td class=lborder>";
recs += cnt + "</td><td class=lborder>";
recs += phyList[test].firstName + "</td><td class=lborder>";
recs += phyList[test].lastName + "</td><td class=lborder>";
recs += phyList[test].title + "</td><td class=lborder>";
recs += phyList[test].specialty[iVar] + "</td><td class=lborder>";
recs += phyList[test].address + "</td><td class=lborder>";
recs += phyList[test].phone + "</td>";
recs += '</tr>';
$('.displayresult tbody').html(recs);
document.getElementById('errorsp').innerHTML = "<i>Match found</i>";
}
cnt++;
}
if (i == dSpecialtyVal){ //$(".dSpecialty").find('option:selected').attr('id')) { //if what's in the phyList array matches selection
recs += "<tr><td class=lborder>";
recs += cnt2 + "</td><td class=lborder>";
recs += phyList[test].firstName + "</td><td class=lborder>";
recs += phyList[test].lastName + "</td><td class=lborder>";
recs += phyList[test].title + "</td><td class=lborder>";
recs += phyList[test].specialty + "</td><td class=lborder>";
recs += phyList[test].address + "</td><td class=lborder>";
recs += phyList[test].phone + "</td>";
recs += '</tr>';
$('.displayresult tbody').html(recs);
document.getElementById('errorsp').innerHTML = "<i>Match found</i>";
cnt2++;
}
$("#splabel").css('font-weight', 'bold');
$("#fname").css('font-weight', 'normal');
$("#lname").css('font-weight', 'normal');
}