我正在尝试选择多项选择测验中可变的 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++;
}
从 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."' />";
我在 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