Changing the value of a jQuery mobile button using jQuery

前端 未结 7 1415
爱一瞬间的悲伤
爱一瞬间的悲伤 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 04:59

    Since jQuery mobile generates HTML around your input type="button" element, and the text that you're seeing isn't actually value of the button, but a text inside of a generated span. You can either traverse the DOM looking for actual span, OR tell jQuery to re-generate button HTML by calling .button("refresh"), like so:

    $("#MyButton").val("changed value");
    $("#MyButton").button("refresh");
    

    The latter is recommended, since it will stay compatible with future versions of jQuery mobile, while traversing the DOM might break if jQuery team chooses to change structure of the HTML generated for the button.

提交回复
热议问题