当我点击div时,我想将其中的文本更改为New Text
。
我如何用jquery
来做到这一点$('#mydiv').????
答案 0 :(得分:3)
$('#mydiv').click(function(){
this.innerHTML = "New Text";
});
如果你有东西需要链接,你可以这样做,
$('#mydiv').click(function() {
$(this).html("New Text") // can include html tags, use .text() for text only.
.animate({marginLeft: '+=10'}); // chain an animation...
});
答案 1 :(得分:2)
绑定一个事件并处理它:
$('#mydiv').click(function() {
$(this).html("New Text");
});
或使用bind
$('#mydiv').bind("click", function() {
$(this).html("New Text");
});
或live
$('#mydiv').live("click", function() {
$(this).html("New Text");
});
<强>参考强>
答案 2 :(得分:1)
$('#mydiv').click(function() {
$(this).html("New Text");
});