87,922
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
<style type="text/css">
.even{background-color:gray;}
.odd{background-color:white;}
</style>
<script type="text/javascript" src="jquery-1.4.4.js"></script>
<script type="text/javascript">
$(function() {
$("#testDiv *").each(function(i) {
$(this).click(function() {
alert($(this).attr("id"));
});
});
});
</script>
</head>
<body>
<form >
<div id = "testDiv">
<button id="button1">button1</button>
<button id="button2">button2</button>
<button id="button3">button3</button>
</div>
<div id="divMsg"></div>
<button id = "testBtn">内容</button>
<p>
我想在 $($("#testDiv").each).bind("click", function(event) {
$("#divMsg").html(
遍历时能够获取所有的子标签对象,然后分别操作 );
});
</p>
</form>
</body>
</html>
我想在 $("#testDiv").bind("click", function(event) {
$("#divMsg").html(
// 绑定click以后,触发点击事件以后,这里this就是元素对象了
this.id
);
});
<div id = "testDiv">
<button id="button1">button1</button>
<button id="button2">button2</button>
<button id="button3">button3</button>
</div>
<div id="divMsg"></div>
<button id = "testBtn">内容</button>
$("#testDiv").each(function() {
$(this).bind('click', function(event){
......
});
);