E.stoppropagation()不起作用 [英] E.stoppropagation() not working

查看:149
本文介绍了E.stoppropagation()不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在#nav_holder里面有几个.nav_buttons。一些导航按钮的禁用属性设置为.attr('禁用',true);



应该发生的是这个;



1.单击启用的导航按钮时,将运行特定方法。

2.单击禁用的导航按钮时,不会发生任何事情。

3.当点击导航持有人时,它应该会崩溃。



实际发生的事情是禁用的按钮仍然是可点击的因为e.stopPropagation()没有停止点击冒泡到nav_holder,导致导航持有者崩溃。



所有以下方法都在运行,所以e。调用stopPropagation()但不起作用。



 $( document )。on('  click'' 。nav_button [disabled]' function (e)
{
// do绝对没有。不工作。
e.stopPropagation();
e.preventDefault();
return false ;
});

$( document )。on(' click'' .nav_button:not([disabled])' function (e)
{
e.stopPropagation();
// 做一些事情,工作正常
});

$(' #nav_holder')。click( function ()
{
// 折叠罚款,但是在点击禁用按钮时不应该发生
});





我不认为它有所作为,但导航按钮不是输入元素,它们是div。



我尝试了什么:



---- -------------------------------------------------- ------------------------

解决方案

document )。on(' click'' .nav_button [disabled]' function (e)
{
// 绝对没有。不工作。
e.stopPropagation ();
e.preventDefault();
return false ;
});


document )。on(' 点击'' .nav_button:not([disabled])' function (e)
{
e.stopPropagation();
// 做一些事情,工作正常
});

' #nav_holder')。click( function ()
{
// 折叠正常,但是当点击禁用按钮时不应该发生
});





我不认为它有所作为,但导航按钮不是输入元素,它们是div。



我尝试了什么:



---- -------------------------------------------------- ------------------------


Hi,

I have several .nav_buttons inside #nav_holder. Some of the nav buttons have had a 'disabled' attribute set with .attr('disabled', true);

What's supposed to happen is this;

1. When an enabled nav button is clicked, a specific method is run.
2. When a disabled nav button is clicked, nothing should happen.
3. When the nav holder is clicked, it should collapse.

What's actually happening is that the disabled buttons are still clickable and cause the nav holder to collapse because e.stopPropagation() isn't stopping the click bubbling up to nav_holder.

All of the following methods are run, so e.stopPropagation() is called but doesn't work.

$(document).on('click', '.nav_button[disabled]', function(e)
{
        // do absolutely nothing. Not working.
        e.stopPropagation();
        e.preventDefault();
        return false;
});

$(document).on('click', '.nav_button:not([disabled])', function(e)
{
        e.stopPropagation();
        // do some stuff, works fine
});

$('#nav_holder').click(function()
{
        // collapses fine, but shouldn't happen when disabled buttons are clicked
});



I don't think it makes a difference, but the nav buttons aren't input elements, they're divs.

What I have tried:

------------------------------------------------------------------------------

解决方案

(document).on('click', '.nav_button[disabled]', function(e) { // do absolutely nothing. Not working. e.stopPropagation(); e.preventDefault(); return false; });


(document).on('click', '.nav_button:not([disabled])', function(e) { e.stopPropagation(); // do some stuff, works fine });


('#nav_holder').click(function() { // collapses fine, but shouldn't happen when disabled buttons are clicked });



I don't think it makes a difference, but the nav buttons aren't input elements, they're divs.

What I have tried:

------------------------------------------------------------------------------


这篇关于E.stoppropagation()不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆