jQuery onclick 事件在 ipad 和平板电脑上不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17161514/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 18:33:04  来源:igfitidea点击:

onclick event is not working on ipad and tablet

jqueryhtmlipadtablet

提问by anam

onClick event not working on tablet,ipad? it is perfectly working on Pc browser but not working for touch events , i tried .binding(),.on() and many thing but they are not giving 100% result.

onClick 事件在平板电脑、ipad 上不起作用?它在 PC 浏览器上完美运行,但不适用于触摸事件,我尝试了 .binding()、.on() 和很多东西,但它们没有给出 100% 的结果。

How can I make it work on ipad , tablet??

我怎样才能让它在 ipad、平板电脑上工作??

<div id="id1" alt='div1' class="sliderImage" width="300" height="360" onclick="" style="visibility:hidden;background-image:url('img/img1.jpg'); border:solid; border-color: black;">You've styled the div to have a set width of 100px. At a reasonable font size, that's too much text to fit in 100px. Without doing anything, </div>
<div id="id2" alt='div2' class="sliderImage" width="300" height="360" onclick="" style="visibility:hidden;background-image:url('img/img2.jpg'); border:solid; border-color: black;">this is 2</div>

回答by Alex Ra?iu

You need to use touchstart i get you a small example,

你需要使用 touchstart 我给你一个小例子,

$('elementid').on('click touchstart', function() {
      console.log('1');
});

The touchstart event is fired when a touch point is placed on the touch surface.

当触摸点放置在触摸表面上时会触发 touchstart 事件。

回答by M Khalid Junaid

You can use tap, swipe, taphold etcevents for the tablets,touch you can do this like

您可以tap, swipe, taphold etc为平板电脑使用事件,触摸您可以这样做

$('htmlelement').bind('click', ClickFunction ).bind('tap', ClickFunction );

Here are the list of jquery mobile events events

以下是 jquery 移动事件事件列表

Also try to use the jquerymobile

也尝试使用jquerymobile

回答by Hitesh

You must have to bind the 'click' or 'tap' event for associated HTML control. You can bind like this

您必须为关联的 HTML 控件绑定 'click' 或 'tap' 事件。你可以这样绑定

$('elementid').bind('click',function() {   alert('Click event triggered'); });

OR

或者

$('elementid').bind('tap',function() {  alert('Tap event triggered'); });