1

I am creating a specialized calculator app with jquery mobile that has a lot of buttons.

My issue is when users tap buttons faster than they can be processed, sometimes taps get queued only to show up as a double tap the next time the button is tapped. A user hits buttons "1", "2", "3" and "4", "1234" should be displayed in another element. Instead you might see "134". And when you tap the "2" again, the display reads "13422". You can tap any number of other keys in the meantime, each getting processed, but the next time you hit "2" the tap event fires twice.

I capture all button taps, then process them based on a data-tag attribute.

    $('button').tap(function (event) {
    var tag = $(this).attr("data-tag")

    switch (tag){
       case "1":
       \\ do stuff
       break;

       case "2":
       //do stuff
       break;

            case "3":
       //do stuff
       break;
     }  
    });

I tried disabling the button during processing and re-enabling them later like this,

     $('button').tap(function (event) {


          $(this).prop('disabled', true).button('refresh');


        // process the taps


         $(this).prop('disabled', false).button('refresh');


    });

but this doesn't fix the problem.

How do I get all queued events to process without this strange trigger of a second tap?

4

1 回答 1

0

我想我已经想通了。event.preventDefault();我在拿起事件后放了一个。

    $('button').tap(function (event) {
         event.preventDefault();
         // do stuff
    )};

这可以防止加倍效应。

唯一的问题是您必须使用 tap,因为event.preventDefault()vclick 无法在计算机而不是 tap 设备上工作。

于 2013-10-13T22:37:28.780 回答