How to make my 'click' function work with iOS

前端 未结 5 1723
面向向阳花
面向向阳花 2020-11-28 11:53

I have a set of Div\'s which act as buttons. These buttons have a simple jquery click() function which works in all browsers except iOS.

For example:



        
5条回答
  •  感情败类
    2020-11-28 12:44

    Actually, the accepted answer did not work for me. I tried using "cursor:pointer", onclick="", and even convert the element to an anchor tag.

    What i did to make it work is to bind the touchstart event insted of the click event. To make it work on all platforms i had to to an ugly ua spoofing like this:

    var ua = navigator.userAgent,
    event = (ua.match(/iPad/i) || ua.match(/iPhone/)) ? "touchstart" : "click";
    
    jQuery("body").on(event, '.clickable_element', function(e) {
        // do something here
    });
    

提交回复
热议问题