Jquery多属性选择器不起作用

时间:2015-06-16 22:35:25

标签: php jquery jquery-selectors

我正在尝试选择2个在多项选择测验中可变的属性。我回答了input中每个问题的正确答案,并没有在页面上显示。我认为我选择2个不同属性的行是问题所在 JQUERY:

        var zz = 1;

        while (zz <= <?php echo $num_rows ?>){  //I'm 100% postive $num_rows returns a value of 3
        var zstring = '#answer' + zz;

        var theanswer = $(zstring).attr('value');  //should return "a" or "c" or whatever the answer is

        if $("input[name=zz][value=theanswer]").is(':checked') {  //this is the line that's not working

              alert("the code worked");
        }       

        zz++;       
        } 

HTML回应PHP

echo "<input type='radio' name=" . $question_number ." value='a'> A. " . $chA . "<br><br>";
echo "<input type='radio' name=" . $question_number ." value='b'> B. " . $chB . "<br><br>";
echo "<input type='radio' name=" . $question_number ." value='c'> C. " . $chC . "<br><br>";
echo "<input type='radio' name=" . $question_number ." value='d'> D. " . $chD . "<br><br>";
echo "<input type='radio' name=" . $question_number ." value='e'> E. " . $chE . "<br>";
echo "<input type='text' id='answer".$question_number."' style='display: none;' value='".$correct."' />";

1 个答案:

答案 0 :(得分:2)

我在if语句中看到你有这个:

if $("input[name=zz][value=theanswer]").is(':checked') {  //this is the line 

它应该是:

if ($('input[name="zz"][value="theanswer"]').is(':checked')) {  //this is the line