【发布时间】:2012-01-30 02:12:34
【问题描述】:
我有以下 jQuery 脚本将复选框转换为 jQuery-UI 按钮并设置要显示的图标。单击按钮时,它还会更改图标。一切正常。但是,我似乎无法找到正确的语法来根据复选框的初始选中状态设置初始图标。
function setCheckBoxImages() {
$(".check-box-image").button({
icons: { primary: 'ui-icon-check' },
text: false
}).change(function () {
$(this).button("option", {
icons: { primary: this.checked ? 'ui-icon-check' : '' }
});
});
};
<input class="check-box-image" type="checkbox" checked="@item.IsBusinessHours" id="checkbox1" disabled/><label for="checkbox1"></label>
编辑: 根据下面的意外天才答案,这是我的最终工作标记和脚本:
@Html.CheckBox(@cbMobileId, @item.IsMobile, new { @class = "check-box-image", disabled = "disabled" })<label for="@cbMobileId">
function setCheckBoxImages() {
var checkboxes= $(".check-box-image");
checkboxes.button({
text: false
}).change(function () {
$(this).button("option", {
icons: { primary: this.checked ? 'ui-icon-check' : 'ui-icon-minus' }
});
});
checkboxes.each(function () {
$(this).change();
});
};
【问题讨论】:
标签: jquery-ui button checkbox icons