首页 > 解决方案 > 如何为 touchstart / touchend 事件禁用按钮?

问题描述

我很惊讶地发现该按钮的 disabled 属性在网站的移动版本上被忽略了。如何禁用 touchstart / touchend 事件的按钮?<button ontouchend="alert();" disabled="disabled" style="touch-event: none">Test for touch</button>触摸后显示alert()并忽略禁用属性。我试图申请touch-event: none风格 - 什么也没发生

UPD。这是一些代码-它是可行的,但不适合简单使用

$("button").on("touchend", function()
{
    if($(this).is(":disabled") == false)
    alert(1)    
});  

标签: javascriptjquerycss

解决方案


我遇到了同样的问题并找到了这个主题。

只要我尝试过,disabled属性 disabled onClick,但没有禁用onTouchStartonTouchEnd.

实际上,onTouchStart并且onTouchEnd不是<button>. 我想这就是原因。


推荐阅读