我有这个页面:
<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>
它正在做的是添加一个链接,我希望能够单击添加的链接并显示一条警报消息,但警报不起作用。我错过了什么?