87,910
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="Scripts/jquery-1.9.1.min.js"></script>
</head>
<body>
<table>
<tr>
<td>
<p id="pclick">点我给页面添加一个按钮</p>
</td>
</tr>
</table>
<script>
$(function () {
$("#pclick").on("click", function () {
$("<input type='button' value='test' id='btnTest' />").insertAfter($(this));
});
$("#btnTest").on("click", function () {
alert("进来了");
});
})
</script>
</body>
</html>
$("<input type='button' value='test' id='btnTest' />").bind('click',function () {
alert("进来了");
}).insertAfter($(this));
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
<body>
<table>
<tr>
<td>
<p id="pclick">点我给页面添加一个按钮</p>
</td>
</tr>
</table>
<script>
$(function () {
$("#pclick").on("click", function () {
var newE=$("<input type='button' value='test' id='btnTest' />").bind('click',function () {
alert("进来了");
});
newE.insertAfter($(this));
});
})
</script>
</body>
</html>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="Scripts/jquery-1.9.1.min.js"></script>
</head>
<body>
<table>
<tr>
<td>
<p id="pclick">点我给页面添加一个按钮</p>
</td>
</tr>
</table>
<div>
<input type="button" name="btnTest" value="我一直都在" />
</div>
<script>
$(function () {
$("#pclick").on("click", function () {
$("<input type='button' value='test' name='btnTest' />").insertAfter($(this));
});
$("td").on("click", "input[name='btnTest']", function () {
alert("进来了td");
});
$("div").on("click", "input[name='btnTest']", function () {
alert("进来了div");
});
$("button").on("click", "input[name='btnTest']", function () {
alert("进不来");
});
})
</script>
</body>
</html>