写在前面
为HTML元素绑定新的事件。
代码
<button id="bind_button">绑定单击事件</button>
<div id="log">日志记录:</div>
<script>
function myBindFunc(e) {
$("#log").html($("#log").html()+"<p>"+e.data.d1+e.data.d2+"</p>");
}
$(function () {
$("#bind_button").bind("click",{d1:"jquery",d2:"已绑定"},myBindFunc);
});
</script>
当选定的HTML元素被单击时,bind函数中传入的参数就会添加到指定的div中。
全文代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>007_jquery</title>
<script src="../../lib/jquery/jquery.js"></script>
</head>
<body>
<button id="bind_button">绑定单击事件</button>
<div id="log">日志记录:</div>
<script>
function myBindFunc(e) {
$("#log").html($("#log").html()+"<p>"+e.data.d1+e.data.d2+"</p>");
}
$(function () {
$("#bind_button").bind("click",{d1:"jquery",d2:"已绑定"},myBindFunc);
});
</script>
</body>
</html>
写在后面
功能比较简单。后续拓展。