使用jQuery更改jQuery移动按钮的值

前端之家收集整理的这篇文章主要介绍了使用jQuery更改jQuery移动按钮的值前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
想知道你能帮助我。我似乎有一个问题,改变我的jQuery Mobile按钮的文本与jQuery。
$("#myButton .ui-btn-text").text("New text");

代码以上建议的相关问题似乎不工作。

也不:

$("#myButton").attr(value,"New Test");

我的按钮的代码如下:

<input type="button" name="answer" id="myButton" data-theme="b" data-answer="4" value="next"></button>

我会喜欢任何反馈的家伙。谢谢

解决方法

更新2
我正在为一个小提琴工作另一个问题,我注意到,与jQuery Mobile 1.0b2的标记是有点不同:
<div data-theme="b" class="ui-btn ui-btn-corner-all ui-shadow ui-btn-down-b ui-btn-hover-b" aria-disabled="false">
    <span class="ui-btn-inner ui-btn-corner-all">
        <span class="ui-btn-text">Show Submit Button</span>
    </span>

    <input type="button" name="answer" id="myButton" data-theme="b" data-answer="4" value="next" class="ui-btn-hidden" aria-disabled="false">
</div>

使用此标记,您需要执行以下操作来更改按钮的文本:

$('#myButton').prev('span').find('span.ui-btn-text').text("Next Text");

更新
信用到期的信用 – 事实证明,@ naugtur的答案这个问题,这与我的编辑完全相同的点,我发现之前,我纠正了我的原始答案。

我不是很熟悉jQuery Mobile和事实,你正在使用< input>对于按钮没有注册时,我最初回答。这里是我更新的答案与一个工作示例,显示你可能如何做到。

在< input type =“button”/>的情况下,jQuery Mobile似乎隐藏< input>元素并创建新的< a>元素被设计为看起来像按钮。这就是为什么当您尝试获取和设置文本使用的<输入>作为选择器,它不工作,因为< span>没有您在屏幕上看到的文字生成标记看起来像这样

<!-- This 'a' button is added dynamically by jQuery Mobile,for the input element that follows it -->
<a role="button" href="#" data-theme="c" class="ui-btn ui-btn-corner-all ui-shadow ui-btn-up-c">
    <span class="ui-btn-inner ui-btn-corner-all">
        <span class="ui-btn-text">My Value</span>
    </span>
</a>

<input type="button" data-role="button" value="My Value" id="myButton" name="answer" class="ui-btn-hidden ui-btn ui-btn-up-c ui-btn-corner-all ui-shadow" tabindex="-1" data-theme="c">
    <span class="ui-btn-inner ui-btn-corner-all">
        <span class="ui-btn-text"></span>
    </span>
</input>

我没有尝试足够的例子是完全自信,但这应该工作

$("#myButton").prev('a').find('span.ui-btn-text').text("New Text")

这里是a working example showing how to change text for both types of buttons(< a>和< input type =“button”>)。

我不建议在< a>按钮,如果你可以帮助它,因为没有id和我的方法,至少,依赖于事实,< a>对应于< input type =“button”/>出现在< input>元件。

原文链接:https://www.f2er.com/jquery/183862.html

猜你在找的jQuery相关文章