0

例子:

    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 />
4

2 回答 2

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 />");
});
于 2013-05-15T18:59:39.127 回答
2

你的身份证是 verify-1 , verify-2...等

for (i=1; i <= 3; i++) 
    $("#verify-" + i).html("Verified as " + i + ".<br />");
于 2013-05-15T19:01:15.643 回答