使用jQuery,如何更改元素的html值? (div) [英] Using jQuery, how do I change the elements html value? (div)
本文介绍了使用jQuery,如何更改元素的html值? (div)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用ajax请求,我想更改div的内容.
Using a ajax request I want to change content of my div.
<div id="d1">202</div>
所以我想将内容更改为其他数字.
So I want to change the content to a different number.
$('d1').InnerText???
另外,说我想增加这个数字,我该怎么做?我必须转换为int吗?
Also, say I wanted to increment the number, how could I do that? Do I have to convert to int?
推荐答案
$("#di").html('My New Text');
查看 jQuery文档.
如果您想增加数字,可以这样做
If you wanted to increment the number, you would do
var theint = parseInt($("#di").html(),10)
theint++;
$("#di").html(theint);
P.S.不知道它是否是错字,但是您需要在选择器中包括#
,以使jQuery知道您正在寻找ID为di
的元素.也许,如果您来自原型,就不会期望到这个,只是让您知道.
P.S. Not sure if it was a typo or not, but you need to include the #
in your selector to let jQuery know you are looking for an element with an ID of di
. Maybe if you come from prototype you do not expect this, just letting you know.
这篇关于使用jQuery,如何更改元素的html值? (div)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文