有这样一段html
<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).bind("click", function(event) {
$("#divMsg").html(
遍历时能够获取所有的子标签对象,然后分别操作 );
});
<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).bind("click", function(event) {
$("#divMsg").html(
遍历时能够获取所有的子标签对象,然后分别操作 );
});
解决方案 »
- 关于JQUERY触发事件的一个问题
- 如何将google地图嵌到自己网页里?
- 输入框必须是数字,并且有最小是1最大是1000的验证。
- 界面可以触发事件,但文件中找不到事件名
- 高手进:js如何提取出符合某一规则的字符串,在线等待,马上给分!
- 请问在一个 key-value 对应的object里能不能按 key 顺序获取 value??
- 如何用JAVASCRIPT设置打印页面啊?求教各位大侠
- onkeyup 在中文输入法下会胡乱触发
- 求输入框验证的一段代码
- 请教:关于从用户输入的名称得到对象(内部已有对象)的方法(30分)
- 动态设置表格单元格的样式及浏览器兼容问题。
- javascript怎样有一个公共缓存区
<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){
......
});
);
$("#divMsg").html(
// 绑定click以后,触发点击事件以后,这里this就是元素对象了
this.id
);
});
$(this).bind('click', function(event){
......
});
如果需要jquery element就用$()包装一下
$(this).bind("click",function(event){ });
})
<!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>