怎么使用jQuery选择某元素而不包括其内部元素
如何使用jQuery选择某元素而不包括其内部元素
我想点击checkbox,但是由于checkbox在td范围内,所以我点击整个td都会触发click事件
如何点击td时触发click,但是点击td内checkbox所在的span不触发click事件呢?
------解决方案--------------------
阻止span的事件冒泡
------解决方案--------------------
------解决方案--------------------
阻止js事件冒泡,在click事件里面加上event.stopPropagation()
我想点击checkbox,但是由于checkbox在td范围内,所以我点击整个td都会触发click事件
如何点击td时触发click,但是点击td内checkbox所在的span不触发click事件呢?
$("td[colspan]").click(function () {
$(".items tr[class=" + $(this).attr("class") + "]").parent().parent().fadeToggle();
});
<tr>
<td class="<%#Eval("bid")%>" colspan="4"><%#Eval("upman") %> 于<%#Eval("uptime") %>上传
<span><input type="checkbox" name="check" value="<%#Eval("bid")%>" /></span>
</td>
</tr>
------解决方案--------------------
阻止span的事件冒泡
------解决方案--------------------
<table>
<tr>
<td class="test" colspan="4">于上传
<span><input type="checkbox" name="check" value="" />span的内容</span>
</td>
</tr>
</table>
<script type="text/javascript">
$(function () {
$("td.test").click(function () {
alert("点击了td");
});
$("td.test").children("span").click(function () {
alert("点击了span");
event.stopPropagation();
});
});
</script>
------解决方案--------------------
阻止js事件冒泡,在click事件里面加上event.stopPropagation()