click event is not working in ipad

笑着哭i 提交于 2019-12-22 17:39:30

问题


Here is my code:

     var tmp = plugin.main_video_src.split("_")[1]

     if(tmp == 2)
     {
        $('.flex-direction-nav .flex-next').click();
     }

This works perfectly in PC browser, But its not working in iPad. Any solution?

Advance Thanks.


回答1:


It could be because you're trying to react to events on an html element that isn't clickable. This tutorial will explain how

Making Elements Clickable

Because of the way Safari on iOS creates events to emulate a mouse, some of your elements may not behave as expected on iOS. In particular, some menus that only use mousemove handlers, as in Listing 6-1, need to be changed because iOS doesn’t recognize them as clickable elements.

Listing 6-1 A menu using a mouseover handler

<span onmouseover = "..."
  onmouseout  = "..."

WHERE TO BUY

</span>

To fix this, add a dummy onclick handler, onclick = "void(0)", so that Safari on iOS recognizes the span element as a clickable element, as shown in Listing 6-2.

Listing 6-2 Adding an onclick handler

<span onmouseover = "..."
  onmouseout  = "..."
  onclick = "void(0)">

WHERE TO BUY

</span>



回答2:


I used "touchstart" event instead of "click" event. It works perfectly for me. Here is the sample code :

$("<selector>").bind("touchstart", function() {

// YOUR CODE ...
});



回答3:


OnClick event doesn't exist on the IPad. You need the touch event

$('.flex-direction-nav .flex-next').trigger('touchstart');

document.addEventListener('touchstart', function(e) {
    //Bind your event here
}, false);

You have the following events

  1. touchstart
  2. touchmove
  3. touchend
  4. touchcancel

How to recognize touch events using jQuery in Safari for iPad? Is it possible?




回答4:


I have the same issue. This is what worked for me.

$('.flex-direction-nav .flex-next').off('click').on('click');


来源:https://stackoverflow.com/questions/15070478/click-event-is-not-working-in-ipad

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!