简体   繁体   中英

button click not working first time in ipad

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.
    }
   });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM