谁错了。我将创建两个按钮,一个是 html,另一个是 jQuery。当我单击“HTML creat”时,会显示消息并创建一个按钮。当我单击“jQuery creat 显示消息。但是当我单击消息中新创建的“我的按钮”按钮时,
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> </script>
<script>
function appendText() {
var button = $("<button>My Button</button>");
$('p').append(button);
}
$(document).ready(function () {
$("button").click(function () {
alert($(this).attr("id"));
});
});
</script>
</head>
<body>
<p>This is a paragraph.<br></p>
<div>
<button onclick="appendText()">HTML creat</button>
</div>
<script>
var button = $("<button>JQuery creat</button>");
$('div').append(button);
</script>
</body>
</html>