简体   繁体   English

jQuery多属性选择器不起作用

[英]Jquery Multiple Attribute Selector not working

I am trying to select for 2 attributes that are variable on a multiple choice quiz. 我正在尝试选择2个在多项选择测验中可变的属性。 I echoed the correct answer to each question in an input that doesn't display on the page. 我在页面上未显示的input中回显了每个问题的正确答案。 I think my line where I select for 2 different attributes is the problem. 我认为我为2种不同属性选择的行就是问题所在。
JQUERY: 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 echoed from PHP 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."' />";

I see that in the if statement you have this: 我在if语句中看到您有以下内容:

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

it should be: 它应该是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM