【问题标题】:Click on (disabled) input not getting triggered on Mozilla单击(禁用)输入未在 Mozilla 上触发
【发布时间】:2021-09-05 02:40:17
【问题描述】:

当我在 Chrome 上单击禁用的输入时,它会给我想要的结果,但在 Mozilla 中,由于禁用的类,它不会呈现任何内容。我该怎么做才能让它发挥作用?

<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script>
        $(document).ready(function(){
            $(".divclick").click(function(){
                alert("jsk");
            });
        });
    </script>
</head>
<body>
    <div class="divclick" height="100px" width="100px" style="background:red;">
        <input type="text" disabled>
    </div>
</body>

Ps:已经尝试在它周围放置一个包装器。我希望只有所需的输入

【问题讨论】:

  • 只是因为它的组件不同,事件是分开的
  • @acarlon 感谢那个,但不幸的是我的处理程序不在输入本身的包装器(div)上。我不打算使用包装
  • @user1560148 您必须使用解决方法,因为 firefox 不会在禁用输入时发出鼠标事件。 Chrome 对其他类型也是如此,例如type="checkbox".

标签: javascript jquery


【解决方案1】:

我遇到了这个帖子https://bugzilla.mozilla.org/show_bug.cgi?id=218093

Firefox, and perhaps other browsers, disable DOM events on form fields that are disabled. 
Any event that starts at the disabled form field is completely canceled and does not propagate up the DOM tree. 
Correct me if I'm wrong, but if you click on the disabled button, 
the source of the event is the disabled button and the click event is completely wiped out. 
The browser literally doesn't know the button got clicked, nor does it pass the click event on. 
It's as if you are clicking on a black hole on the web page.

来源在这里Click event doesn't fire for disabled text field?

这里是Demo

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-13
    • 1970-01-01
    相关资源
    最近更新 更多