示例:
for (i=1; i <= 3; i++) {
alert(i + "," + wanted);
$("#hint-" + $i).html("Verified as " + $i + ".<br />");
}
更改此内容:
<div id="verify-1"> </div>
<input type="radio" name="b_answer_1" id="radio-1" value="Lamb">Lamb</input><br />
<div id="verify-2"> </div>
<input type="radio" name="b_answer_2" id="radio-2" value="Llama">Llama</input><br />
<div id="verify-3"> </div>
<input type="radio" name="b_answer_3" id="radio-3" value="Goat">Goat</input><br />
对此:
<div id="verify-1">Verified as 1<br /></div>
<input type="radio" name="b_answer_1" id="radio-1" value="Lamb">Lamb</input><br />
<div id="verify-2">Verified as 2<br /></div>
<input type="radio" name="b_answer_2" id="radio-2" value="Llama">Llama</input><br />
<div id="verify-3">Verified as 3<br /></div>
<input type="radio" name="b_answer_3" id="radio-3" value="Goat">Goat</input><br />
答案 0 :(得分:3)
在$
i
for (i=1; i <= 3; i++) {
alert(i + "," + wanted);
$("#verify-" + i).html("Verified as " + i + ".<br />");
}
或者你可以这样做 -
$("div[id^='verify-']").each(function(){
var num = this.id.match(/(\d+)$/)[1];
$(this).html("Verified as " + num + ".<br />");
});
答案 1 :(得分:2)
您的ID是verify-1 , verify-2
...等
for (i=1; i <= 3; i++)
$("#verify-" + i).html("Verified as " + i + ".<br />");