我有这个页面:jQuery的追加和方法
<html>
<head></head>
<body>
<div id="elem"></div>
<button id="addElem">Add Element</button>
<script src="jquery-1.9.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
//add element to elem div
$("#addElem").click(function() {
$("#elem").append('<a id="test" href="#">this is a test</a><br />');
});
//remove added elements on click event
$("#test").on("click", function(){
alert(12);
});
});
</script>
</body>
</html>
它在做什么,是添加一个链接,我希望能够点击添加的链接,并显示一条警告消息,但警报不管用。我错过了什么?
可能重复[.delegate()VS。对()] (http://stackoverflow.com/questions/8359085/delegate-vs-on)您没有使用.on的委托事件的正确语法。你现在的用法和使用'.click(function(){...' – 2013-05-01 20:56:57
)是一样的吗?jquery运行前的问题* * #test元素是否可用? – keithwyland 2013-05-01 20:58:58