【发布时间】:2013-04-23 14:48:05
【问题描述】:
当我使用 .html() 放置数据时,jQuery 脚本无法处理新数据。 代码是这样的:
<html>
<head>
<script>
$(document).ready(function(){
$("#newhtml").on("click", function(){
alert("I'm the NEW one!");
});
$("#put_new").on("click", function(){
$("#newdiv").html("<input type = 'button' id = 'newhtml' value = 'click on me'/>");
});
});
</script>
</head>
<body>
<div id="newdiv"></div>
<input type="button" id="put_new" value="put new html" />
</body>
</html>
这是一个简单的示例,但我想要放置更多数据,并且我希望新元素以这种方式与脚本一起使用。 我试图在 stackoverflow.com 上搜索,但没有找到任何适用的。 非常感谢。
【问题讨论】:
-
我已经回答了一个类似的问题。可能会对正在发生的事情/如何避免它有所了解:stackoverflow.com/questions/12468847/…
-
谢谢,我去看看:)
标签: javascript jquery html