Javascript 按钮onClick在移动设备上不起作用

Javascript 按钮onClick在移动设备上不起作用,javascript,jquery,mobile,touch,Javascript,Jquery,Mobile,Touch,我试了很多东西: 然而,一切似乎都不起作用 以下是我所拥有的: #modal-close {cursor:pointer;} <button class="button" id="modal-close">ok</button> function hideModal(){ var modal = document.getElementById('modal'); modal.style.display = 'none'; } $(functio

我试了很多东西:

然而,一切似乎都不起作用

以下是我所拥有的:

#modal-close {cursor:pointer;}

<button class="button" id="modal-close">ok</button>

function hideModal(){
    var modal = document.getElementById('modal');
    modal.style.display = 'none';
}

 $(function() {
        $('#modal-close').on('click touchstart',function (e) {
            hideModal();
            })
        });
#模式关闭{光标:指针;}
好啊
函数hideModal(){
var modal=document.getElementById('modal');
modal.style.display='none';
}
$(函数(){
$(“#模式关闭”)。在('单击touchstart',函数(e){
hideModal();
})
});

我可能做错了什么?

将按钮的id更改为modal\u close。这可能对你有用。id值的作用类似于标识符,因此有一条规则,即我们不能使用每个符号来命名标识符。

 #modal-close {cursor:pointer;}

<button class="button" id="modal-close">ok</button>

function hideModal(){
    var modal = document.getElementById('modal');
    modal.style.display = 'none';
}

 $(function() {
        $('#modal-close').on('click touchstart',function (e) {
            hideModal();
            })
        });
#模式关闭{光标:指针;}
好啊
函数hideModal(){
var modal=document.getElementById('modal');
modal.style.display='none';
}
$(函数(){
$(“#模式关闭”)。在('单击touchstart',函数(e){
hideModal();
})
});
有效


吸引我的是
hideModal()
,它使用
classList
添加或删除类。我把它切换到
className+=
,它按预期工作

使用这个“$”(“#modal close”)。在('click touchtstart',function(){hideModal();})上,我在ios上看到了这个问题。触摸会触发悬停状态,而不是触发单击事件。我相信我们用这个来解决这个问题:@RashidJaved没有work@RobertBroden您只是简单地包含了它,还是包含了其他代码?@blue\u zing其他开发人员也包含了它。它似乎有一个解释如何实现它的用法部分