问题描述:

This is my html code

 < button class="send-report" name="submit" id="submit" type="submit" onclick="reportfeed()">Send Report< /button>

On the first click the keyboard disappeared, the 'reportfeed' function works only in the second click (in ipad)

function reportfeed()

{

alert(1);

}

I can use the code below, Please help me if you know any other method

jQuery(".send-report").bind("click touchstart", function(){

reportfeed();

});

网友答案:

Define a clickhandler that you can use later on:

var clickHandler = ('ontouchstart' in document.documentElement ? "touchstart" : "click");

$(".send-report").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.

Use .on() because .bind() will be removed from future scripts,I think.

网友答案:

Try this

$(".send-report").on('touchstart click', function(){
 reportfeed();
});

You could use .stopPropagation() to stop multiple events being fired. Also, if you want to do specific stuff for different event types use e.type

 $('.send-report').on('touchstart click', function(e) {    
    e.stopPropagation(); //stops propagation
    if(e.type == "touchstart") {
      // Handle touchstart event.
    } else if(e.type == "click") {
       // Handle click event.
    }
   });
相关阅读:
Top