cordova/phonegap onclick doesn't work

前端 未结 7 2056
小鲜肉
小鲜肉 2021-01-21 14:34

I try to create button which starts an alert after a click event. Something like that :

    
    

Apache

7条回答
  •  感动是毒
    2021-01-21 15:31

    Define a clickhandler that you can use later on:

    var clickHandler = ('ontouchstart' in document.documentElement ? "touchstart" : "click");
    
    $("a").bind(clickHandler, function(e) {
        alert("clicked or tapped. This button used: " + clickHandler);
    });
    

    This will trigger click on non-touch devices and touchstart on touch devices.

    When that is said, I will strongly recommend using Fast click instead, and use regular click-events. With the above solution, you will trigger "touchstart" on links when you swipe on it to scroll the page for instance - which is not ideal.

提交回复
热议问题