如何更换jQueryUI的按钮上的文字? [英] How do I replace jQueryUI button text?

查看:180
本文介绍了如何更换jQueryUI的按钮上的文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到了我jQueryUI的使用按钮somethink像这样(简化)。

I've got a button that I use with jQueryUI somethink like this (simplified).

<button id="mybutton">Play<button>
<script>
$("#mybutton").button().toggle(
    function(){
       $(this).text('Stop');
    },
    function(){
       $(this).text('Start');
    },
);
</script>

这code打破了按钮的外观,因为使它成为按钮窗口小部件时,有个按钮,里面增加了一个新跨越的方式。所以我现在改变这样的按钮值

This code breaks the way the button looks because when making it into the button widget, there's a new span added inside the button. So I'm changing the button value like this now

$(this).find('span').text('Stop');

这是哈克,因为我不能把按钮作为一个黑盒子了,不得不往里走。

This is hacky because I can't treat the button as a black box anymore and have to go inside.

有没有干净的方式做到这一点?

推荐答案

也许你可以使用标签的jQuery用户界面按钮的选项现在呢?

Maybe you could use the label option of the jQuery UI button now instead?

$("#mybutton").button().toggle(function() {
   $(this).button('option', 'label', 'Stop');
}, function() {
   $(this).button('option', 'label', 'Start');
});

jsbin preVIEW这里

这篇关于如何更换jQueryUI的按钮上的文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆