How do you remove a button's active state with jQuery Mobile?

后端 未结 8 1025
温柔的废话
温柔的废话 2020-12-03 07:31

In my mobile app, using jQuery Mobile...

  • I would like to make a simple button execute a simple javascript function on click. No page transitions, nothing sp

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-03 08:18

    I have spent the good part of a day and night finding the answer to this problem mainly occurring on an android running phonegap. Instead of the standard JQM buttons I am using custom images with :active state in CSS. After following the link to the next page, then clicking back, the button would just stay in the :active state. I have tried adding classes and removing classes and various other suggestions and nothing has worked.

    So I came up with my own little fix which works a treat and may help anyone else that is sitting here stumped. I simply call this snippet of code on 'pagecontainerchange' using data.toPage[0].id to only call it on the page where the active state stuck is occurring. Just make sure to wrap your buttons in a div, in my case called "themenu".

    function ResetMenu() {
    var menuHtml = $("#themenu").html();
    $("#themenu").empty().html(menuHtml).trigger("create");
    

    }

提交回复
热议问题