我想使用 ajax 请求更改我的 div 的内容。
<div id="d1">202</div>
所以我想把内容改成不同的数字。
$('d1').InnerText???
另外,假设我想增加数字,我该怎么做?我必须转换为 int 吗?
最佳答案
$("#di").html('My New Text');
查看 jQuery documentation .
如果你想增加数字,你会这样做
var theint = parseInt($("#di").html(),10)
theint++;
$("#di").html(theint);
附言不确定这是否是拼写错误,但您需要在选择器中包含 #
以让 jQuery 知道您正在寻找 ID 为 di
的元素。也许如果你来自原型(prototype),你不会期望这一点,只是让你知道。
关于javascript - 使用 jQuery,如何更改元素的 html 值? (div),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/537554/