【问题标题】:Jquery Multiple Attribute Selector not workingJquery 多属性选择器不起作用
【发布时间】:2015-09-01 23:17:55
【问题描述】:

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

        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++;       
        } 

从 PHP 回显的 HTML

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."' />";

【问题讨论】:

    标签: php jquery jquery-selectors


    【解决方案1】:

    我在 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 
    

    【讨论】:

    猜你喜欢
    • 2011-08-29
    • 2014-03-28
    • 2019-10-06
    • 2015-05-13
    • 2017-05-21
    • 2019-09-08
    • 2014-02-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多