<script> $(function() { $( "#dynabutton" ).button( { icons: { primary: "ui-icon-gear" },text: false }); $( "#swap" ).button( { icons: { primary: "ui-icon-locked" },text: true }).click(function(event) { // change #dynabutton icon from // "ui-icon-gear" // to: // "ui-icon-locked" }); }); </script> <div class="demo"> <button id="dynamic_button">Button with gear icon</button> <button id="swap">Swap icons</button> </div>
单击#swap按钮,我想将与#dynabutton相关联的图标(jQueryUI icon)从ui-icon-gear切换到ui-icon-locked.
但我不知道这是否得到支持?
解决方法
您可以稍后调用
.button("option",options)
来设置选项(与其他jQuery UI小部件一样),包括图标:
$(function() { $( "#dynabutton" ).button({ icons: { primary: "ui-icon-gear" },text: false }); $( "#swap" ).button({ icons: { primary: "ui-icon-locked" },text: true }).click(function() { $( "#dynabutton" ).button("option",{ icons: { primary: "ui-icon-locked" } }); }); });