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

あなたのIDは verify-1 , verify-2...などです

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