Changing the value of a jQuery mobile button using jQuery

前端 未结 7 1411
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-05 04:49

Wondering if you can help me out. I seem to have a problem changing the text of my jQuery Mobile buttons with jQuery.

$(\"#myButton .ui-btn-text\").text(\"New te         


        
7条回答
  •  滥情空心
    2021-02-05 05:21

    With jquery.mobile-1.1.0 I was experiencing something slightly different and had trouble sifting through the responses to find a workable answer. I've documented the problems I experienced and the solution I found below.

    Snippet 1

    
    

    With this, I'm able to change the text, but the method clears out the added spans and classes, thus compressing the button.

    button image

    HTML

    
    

    Snippet 2

    
    

    This had no effect upon the button text.

    button image

    HTML

    
    

    Snippet 3

    
    

    This generated the following error message:

    cannot call methods on button prior to initialization; attempted to call method 'refresh'

    Which was confusing to me because this function is being called only after the page is initialized. Reading further, I then noticed Priyank's reference to a working answer at stackoverflow.com/a/7279843/61821

    Snippet 4 - Working

    
    

    A better jQuery selector works like a charm.

提交回复
热议问题