Change button text jquery mobile

后端 未结 10 880
傲寒
傲寒 2020-11-29 04:32

I\'m using the new jquery mobile 1.0 alpha 1 release to build a mobile app and I need to be able to toggle the text of a button. Toggling the text works fine, but as soon a

相关标签:
10条回答
  • 2020-11-29 05:16

    I read through this and various options online and think I may have a simpler solution. It definitely works for links you are turning into a button with the data-role="button" attribute.

    Simply put the text of the button in a separate span, and then change the contents of the span in your JavaScript.

    e.g.

    <a data-role="button" href="#" id="consumed"><span id="oldBtnText">Mark Old</span></a>
    

    Then a simple

    $('#oldBtnText').html("Old");
    

    Will do the job. It also shouldn't be a problem if jQuery changes their structure.

    0 讨论(0)
  • 2020-11-29 05:18
    <a data-role="button" href="#" id="consumed">Mark Old</a>
    

    You want to:

    $('#consumed').text('Mark New');
    $('#consumed').button('refresh');
    

    The reason is to enable your changes to be backwards-compatible with future versions of jQuery mobile.

    0 讨论(0)
  • 2020-11-29 05:19

    This works for me:

    $('#idOfOriginalButton').prev('.ui-btn-inner').children('.ui-btn-text').html('new text');
    

    solution from: http://forum.jquery.com/topic/changing-text-works-except-for-buttons

    0 讨论(0)
  • 2020-11-29 05:19

    As of JQM 1.3.1 (maybe earlier?) simple .text() seems to be supported.

    0 讨论(0)
提交回复
热议问题