我有一個div,其內容會從innerHTML的動態生成,我似乎無法針對使用jQuery進行驗證這些元素從innerHTML的或.html()設置元素,例如,這是網頁:如何指定使用jQuery
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<head>
</head>
<body>
<span id="alert1">Alert1</span>
<input type="button" value="Click Me" id="button1" />
<div id="empty"></div>
</body>
</html>
,這是js代碼:
<script type = "text/javascript">
$(document).ready(function() {
$('#button1').click(function() {
var html = "uname <input type='text' id='uname'><br />password <input type='text' id='password'><br /><span id='alert'>Alert</span>";
$('#empty').html(html);
});
$('#alert').click(function() {
alert('Alert');
});
$('#alert1').click(function() {
alert('Alert1');
});
});
</script>
與ID alert1的作品跨度但ID警報的警報,其使用的innerHTML或.html()不工作,那麼如何解決這一問題設定?
預先感謝您