<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
。
但我不知道这是否得到支持?
答案 0 :(得分:22)
您可以稍后调用.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" }
});
});
});