This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center
                            
                        
                    
                
                6年前关闭。
            
        

请参见以下页面进行实时演示:Live Demo

如果从“专业”中选择“麻醉科”,然后单击“搜索”,则除计数外,其他所有功能均正常。我正在计算行数。像这样:

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');
            }

最佳答案

我不太了解您要执行的操作,请描述在(i [iVar] == dSpecialtyVal)和if (i == dSpecialtyVal)for testfor iVar循环的情况下要达到的目标。

可能的问题:


在第二种情况(if (i == dSpecialtyVal))中,您不是
递增cnt2 ++,但递增cnt ++。这很奇怪,因为您在其中显示cnt2
在这种情况下,它将始终等于1。
而且,如果您要增加cnt2,它将无用,因为
if (i == dSpecialtyVal)不在for iVar循环中,并且cnt和
for test开头将cnt2重置为值1
环。尝试将var cnt2 = 1;移到for test语句之前。

关于javascript - JQuery中的行数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16488125/

10-10 12:56