gpt4 book ai didi

javascript - 如何使用 jQuery 更改 DIV 中的 HTML?

转载 作者:太空宇宙 更新时间:2023-11-03 20:50:29 25 4
gpt4 key购买 nike

例子:

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

最佳答案

删除 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 />");
});

关于javascript - 如何使用 jQuery 更改 DIV 中的 HTML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16572951/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com