如何在jQuery mobile中更改按钮文本

how to change a button text in jQuery mobile

本文关键字:按钮 文本 mobile jQuery      更新时间:2023-09-26

可能重复:
使用jquerymobile更改按钮上的文本。

我需要更改一个按钮文本,我正在使用jQuery手机。

这是我的html:

<fieldset>
    <div><button type="submit" id="login_var">Login</button></div>
    <div><button type="reset" >Reset</button></div>
</fieldset>

我已经尝试了本页上的所有示例:链接,我什么都不工作。

请帮助

我以前也做过同样的事情,但做起来并不像应该做的那么明显。由于jQM在按钮中添加了span标签,因此需要更改span:中的值

$("#login_var .ui-btn-text").text("NewText");

同样,如果你想更改图标,你可以这样做:

$("#login_var .ui-icon").removeClass("ui-icon-arrow-l").addClass("ui-icon-arrow-r");

编辑:很抱歉,我刚刚注意到你在问题中发布的链接有相同的解决方案,而你说这对你不起作用。也许如果你把按钮改成

<a data-role="button"></a>

而不是<button></button>

是的,你可以使用

$(function(){
  $('#login_var').text('Ok').button('refresh');
});

根据http://jquerymobile.com/test/docs/buttons/buttons-methods.html,在一个按钮上只能调用三个方法。