jQuery-UI .button()导致问题

时间:2014-04-25 11:34:40

标签: javascript jquery jquery-ui

这很奇怪,完全出乎意料。在我的fiddle here中,如果我这样做,代码就无效了

$("#id").button().click(function(){  
    ...
});

如果我这样做,

$("#id").click(function(){  
    ...
});

我错过了什么?作为参考,我使用了this

jsFiddle

1 个答案:

答案 0 :(得分:1)

问题是当您尝试获取正在使用的按钮文本时

$(this).html() // it's giving you the html of the button as <span class="ui-button-text">Start</span>

使用

$(this).text()

DEMO

<强>更新

使用

$(this).html("<span class='ui-button-text'>Resume</span>");

Insted of

$(this).html("Resume");

这应该针对所有其他按钮文本进行更改,即“开始”,“暂停”。