jquery ui按钮图像没有更改

jquery ui button image is not changing

本文关键字:图像 ui 按钮 jquery      更新时间:2023-09-26

我想根据我与元素一起存储的数据更改jquery ui按钮图像,为此我尝试了:

 $(document).ready(function(){                                                               
     $("#ppbutton").button({ icons: { primary: 'ui-icon-play'} }); 
 });
 /* this code is from inside function(e) where e is eventobject */
 var state = $(e.currentTarget).attr("data-state");
 state == "pause" ? 
    $("#ppbutton").button("option", "icons", { primary: "ui-icon-play" }) :
    $("#ppbutton").button("option", "icons", { primary: "ui-icon-pause" });

但是上面的代码并没有改变按钮的图像。我不能在这里使用toggleClass,因为没有必要,每次调用函数时,图像都会发生变化。请帮帮我?

要更新图像属性,需要运行$("#ppbutton").button( "refresh" )方法

http://jqueryui.com/demos/button/#method-刷新

进行一天的