我只是新的jquery,而在jQuery上做实验时我遇到了这个问题 - >它可以将html插入到div中,但点击函数不能处理插入的html。有人知道为什么在此先感谢Onclick函数不能在插入的HTML上工作
$(document).ready(function(){
$("#insertTest").click(function(){
$("#testDiv").html($("#testDiv").html() + '<p><a href="#" class="testClick">Click Me</a></p>');
});
$(".testClick").click(function(){
alert('Ahoy');
});
});
<a href="#" id="insertTest">Click to Insert</a>
<div id="testDiv">
</div>
由于jQuery 1.7中.live()已被弃用在fav或.on()。 – j08691 2012-03-19 02:58:07
谢谢,更新OP – 2012-03-19 03:00:06
我已经发现了**。live **,它的工作原理,感谢所有的反馈人员,我真的很喜欢它,再次感谢 – 2012-03-19 03:39:15