<script type="text/javascript">
$(function(){
$(':radio').each(function(){
$(this).bind('click',function(){
alert($(this).val());
});
});
$('tr').bind(function(){
$(this).children(':radio').click();
});
});
</script>
</head><body>
<table cellspacing="1">
<tr>
<th>编号</th>
<th>姓名</th>
</tr>
<tr>
<td><input type="radio" name="sel" id="sel1" /><label for="sel1">1</label></td>
<td>Danie</td>
</tr>
<tr>
<td><input type="radio" name="sel" id="sel2" /><label for="sel2">2</label></td>
<td>Jack</td>
</tr>
<tr>
<td><input type="radio" name="sel" id="sel3" /><label for="sel3">3</label></td>
<td>Tom</td>
</tr>
<tr>
<td><input type="radio" name="sel" id="sel4" /><label for="sel4">4</label></td>
<td>David</td>
</tr>
</table>想实现单击行时,就去点击它其中的radio,为何会提示错误?
tr的click事件中加上这段
var e = e ? e : window.event;
if (window.event) { // IE
e.cancelBubble = true;
} else { // FF
//e.preventDefault();
e.stopPropagation();
} 也不行。
$(function(){
$(':radio').each(function(){
$(this).bind('click',function(){
alert($(this).val());
});
});
$('tr').bind(function(){
$(this).children(':radio').click();
});
});
</script>
</head><body>
<table cellspacing="1">
<tr>
<th>编号</th>
<th>姓名</th>
</tr>
<tr>
<td><input type="radio" name="sel" id="sel1" /><label for="sel1">1</label></td>
<td>Danie</td>
</tr>
<tr>
<td><input type="radio" name="sel" id="sel2" /><label for="sel2">2</label></td>
<td>Jack</td>
</tr>
<tr>
<td><input type="radio" name="sel" id="sel3" /><label for="sel3">3</label></td>
<td>Tom</td>
</tr>
<tr>
<td><input type="radio" name="sel" id="sel4" /><label for="sel4">4</label></td>
<td>David</td>
</tr>
</table>想实现单击行时,就去点击它其中的radio,为何会提示错误?
tr的click事件中加上这段
var e = e ? e : window.event;
if (window.event) { // IE
e.cancelBubble = true;
} else { // FF
//e.preventDefault();
e.stopPropagation();
} 也不行。
解决方案 »
- 右下角弹窗怎么弄啊?
- 大家能创建出来嘛
- onbeforeunload事件中 怎样捕捉cancel事件
- 怎么让div根据里面内容的大小变化?
- 求助,父页面问题,可能需要高手?
- 正则表达式的问题,/^\d*$/g 为判断输入一定要为数字,但如果为空便可跳过判断,如何修改让其输入为空时仍无法通过判断
- 请教JS读取目录名问题
- window.opener.location.reload()请问?
- 如何可以将windows 2000 server的C、D等盘的默认共享属性去除,可不可以将这个属性永久去除,因为选择“右击”-“共享”去除后,重启又出
- 页面元素滚轮缩放问题
- 最近正在做的几个js功能,大家给点帮忙,谢谢
- jquery的问题
$('#myid').click(function(event){
event.preventDefault();
})jQuery做了多浏览器支持, 你给个event参数进去, 然后调preventDefault, 在IE下也会执行。(因为实际上这个event变量已经不是那个event变量了)
event.preventDefault();
})
++阻止泡泡的通用方法,没有浏览器区别!
event.stopPropagation();
});
$(function(){
$(':radio').each(function(){
$(this).bind('click',function(){
alert($(this).val());
return false;
});
});
$('tr').bind(function(){
$(this).children(':radio').click(function () {return false;});//return false;阻止冒泡
});
});
$(function(){
$('tr').bind('click',function(){
this.children.item(0).children.item(0).click();
// $(this).children(':radio').click();
// alert($(this).children(':radio').val());
});
$(':radio').bind('click',function(event){
event.stopPropagation();
alert($(this).val());
});
});
</script>
这样可以