【问题标题】:Setting of "Disabled" Property in jQuery Not Working for Touch EventjQuery 中“禁用”属性的设置不适用于触摸事件
【发布时间】:2013-07-25 14:24:14
【问题描述】:

例如一段jQuery代码:

$("#my_button").prop("disabled", true);

代码可以阻止按钮正确响应鼠标点击事件。但是,无论“禁用”属性的设置如何,按钮都会继续响应移动设备上的触摸事件。

所以我想知道是否有办法通过阻止按钮或其他元素响应所有用户交互来完全禁用它们。非常感谢!

【问题讨论】:

    标签: jquery properties touch element


    【解决方案1】:

    你可以.unbind()所有事件监听器

    【讨论】:

    • 我注意到我使用了:$(document).on("touchstart", "#my_button", function(event) {...}) 来定义事件处理程序来处理#my_button 上的触摸事件。这个表单是否和$("my_button").on("touchstart", function(event) {...})? Can the code $("my_button").off("touchstart") 一样去掉$(document).on("touchstart", "#my_button", function(event) {...})设置的事件处理函数?谢谢!
    • 1.当您使用$(document).on("touchstart", "#my_button", function(event) {...}) 时,#my_button 元素上发生事件,然后冒泡到文档元素。将触发文档处理程序。在第二种情况下,事件发生在 #my_button 元素上并由 #my_button 元素处理程序处理。 2.你不能通过这样做$("my_button").off("touchstart")来禁用处理程序,因为它是在文档元素上而不是在#my_button上注册的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-24
    • 2011-12-11
    • 1970-01-01
    • 2015-04-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多