Jquery 如何更正此变量

Jquery 如何更正此变量,jquery,Jquery,我有一个可变的问题如下: function validation() { var context = $('#optionAndAnswer'); var currenttotal = context.find('.answerBtnsOn').length; alertValidation= ""; // Note, this is just so it's declared... $(".numberAn

我有一个可变的问题如下:

 function validation() {

                var context = $('#optionAndAnswer');
    var currenttotal = context.find('.answerBtnsOn').length;    

    alertValidation= "";
        // Note, this is just so it's declared...

    $(".numberAnswerTxtRow").each(function() {
    if (!this.value) {
        alertValidation += "\nPlease Enter in the Number of Answers you Require for this question\n";
    }
else if (currenttotal > $(this).val()){
    alertValidation += "\nYou have selected more answers than the required amount\n";
}

else if (currenttotal < $(this).val()) {
    alertValidation += "\nYou have selected less answers than the required amount\n";
}
});
这些行被添加到称为QANDABL的表中:

<table id="qandatbl" align="center">
<thead>
<tr>
    <th class="noofanswers">Number of Answers</th>
    <th class="answer">Answer</th>
</tr>
</thead>
<tbody></tbody>
</table>

答案数目
答复

您的代码看起来有点复杂,仍然缺少一些部分,所以我只能猜测。。。你为什么不看看你的变量里有什么。这将有助于你找到答案:

var context = $('#optionAndAnswer');
console.log(context);
var currenttotal = context.find('.answerBtnsOn').length;  
console.log(context.find('.answerBtnsOn'));

你的问题有点不具体。你试过调试你的JS代码吗?您可以使用Firebug或类似工具来执行此操作。只需将jQuery选择器粘贴到控制台中,它就会显示返回值——使用这种方法,您可以看到选择器是否返回了正确的元素。
var context = $('#optionAndAnswer');
console.log(context);
var currenttotal = context.find('.answerBtnsOn').length;  
console.log(context.find('.answerBtnsOn'));