Javascript jQuery stopPropagation不工作!
我完全被难住了,我看了很多类似的问题,但我不明白为什么这个点击事件一直在传播 代码如下:Javascript jQuery stopPropagation不工作!,javascript,jquery,events,javascript-events,Javascript,Jquery,Events,Javascript Events,我完全被难住了,我看了很多类似的问题,但我不明白为什么这个点击事件一直在传播 代码如下: $("#view-radio").buttonset().bind('click', function(e) { redraw(Testimonials); e.stopPropagation(); }); 这是单选按钮 <div id="view-radio" class="i-obj buttonset"> <inp
$("#view-radio").buttonset().bind('click', function(e) {
redraw(Testimonials);
e.stopPropagation();
});
这是单选按钮
<div id="view-radio" class="i-obj buttonset">
<input type="radio" id="gridradio" name="view-radio" checked="checked" value="grid" />
<label for="gridradio"> <img src="http://SwolePersonalTraining.com/beta/wp-content/themes/striking/images/gridview.jpg" class="icon">Grid View</label>
<input type="radio" id="listradio" name="view-radio" value="list" />
<label for="listradio"><img src="http://SwolePersonalTraining.com/beta/wp-content/themes/striking/images/listview.jpg" class="icon">List View</label>
</div>
网格视图
列表视图
您可以在此处找到正在运行的页面:
以下是完整的代码:
有什么想法吗?我不能发誓,因为很难在您的实时站点上进行测试,但我认为现在发生的是,您绑定了
查看单选按钮的单击事件,而不是其中的两个单选按钮
我想试试这样的东西:
$("#view-radio").buttonset(). // Turn radio buttons of the div in a buttonset
find('input').bind('click', // Bind the click event of each of the two radios
....
编辑:
对!!它起作用了!
不需要停止播放(阅读其他答案以了解原因)。您是否尝试过简单地返回false代码>而不是e.stopPropagation()代码>?什么是“推荐书”?看起来那应该是一根绳子。可能是由于语法错误导致了e.stopPropagation()代码>正在执行的调用。您希望使用e.stopPropagation()完成什么代码>?如您所见,当我按下单选按钮两次时,它将调用redraw()函数。它应该只调用一次。返回false;使其被调用一次,但buttonset值不变。所以,即使你们点击列表,它仍然在网格上。