jquery label和radio 要阻止冒泡该怎么实现,return false不行 jquery label阻止冒泡jsradio 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你这跟jQuery 没关系。return false 是阻止默认事件的。再说,你放的那个位置,能阻止。再看看书吧,再写写代码吧。<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Insert title here</title><style>#lv0{ }#lv1{ width:200px; height:200px; background-color:red;}#lv2{ width:100px; height:100px; background-color:blue;}</style></head><body id='lv0'><div id='lv1'>this is a test<div id='lv2'>lv2</div></div><script>function $(id){ return document.getElementById(id);}$('lv0').onclick = function(e){ }$('lv1').onclick = function(e){ }$('lv2').onclick = function(e){ e.preventDefault(); e.stopPropagation();}</script></body></html> 楼上正解,我再补充两句有人认为 return false = stopPropagation() + preventDefault(), 其实是错的. return false 不但阻止事件, 还可以返回对象, 跳出循环等… 方便地一刀切而不够灵活, 滥用易出错.但是不要滥用他,尤其是在复杂的页面时,你会被这个return false搞疯的 楼主,label有个for属性的,可以减少你的烦恼,请看示例代码:<!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><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><script src="jquery-ui-1.10.4.custom/js/jquery-1.10.2.js"></script></head><body><ul><li ><input type="radio" name="financingType" id="financingType" value="00101" /><label id="label1" for="financingType">项目融资</label></li><li ><input type="radio" name="financingType" id="financingType2" value="00102" /><label id="label1" for="financingType2">项目融资222</label></li></ul><script>$(function(){ $("[name='financingType']").click(function(){ alert("value:"+$(this).val()); });});</script></body></html> 问题自己解决,送分~~~!!要分的速来!!!! 关于 $ 关于insertRow后 是否能为对象添加onclick事件 高手们都放假了吗?小妹请教个问题。 DIV里面的flash不跟着DIV动 推荐比较好的JS类库 Javascript的代码在记事本里阅读起来挺费劲的,有什么好的格式化工具么? 50分求救一个简单问题,解决就给分,在线等! Windows的字体对话框? 关于字符串截取问题 请教 js 引号的替换 楼主怒了!setTimeout调用类成员函数,气死人啊!
return false 是阻止默认事件的。再说,你放的那个位置,能阻止。再看看书吧,再写写代码吧。<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
#lv0{
}
#lv1{
width:200px;
height:200px;
background-color:red;
}
#lv2{
width:100px;
height:100px;
background-color:blue;
}
</style>
</head>
<body id='lv0'>
<div id='lv1'>this is a test
<div id='lv2'>lv2</div>
</div><script>
function $(id){
return document.getElementById(id);
}
$('lv0').onclick = function(e){
}
$('lv1').onclick = function(e){
}
$('lv2').onclick = function(e){
e.preventDefault();
e.stopPropagation();
}</script></body>
</html>
有人认为 return false = stopPropagation() + preventDefault(), 其实是错的.
return false 不但阻止事件, 还可以返回对象, 跳出循环等… 方便地一刀切而不够灵活, 滥用易出错.
但是不要滥用他,尤其是在复杂的页面时,你会被这个return false搞疯的
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="jquery-ui-1.10.4.custom/js/jquery-1.10.2.js"></script>
</head><body>
<ul>
<li >
<input type="radio" name="financingType" id="financingType" value="00101" />
<label id="label1" for="financingType">项目融资</label>
</li>
<li >
<input type="radio" name="financingType" id="financingType2" value="00102" />
<label id="label1" for="financingType2">项目融资222</label>
</li>
</ul>
<script>
$(function(){
$("[name='financingType']").click(function(){
alert("value:"+$(this).val());
});
});
</script>
</body>
</html>