我有以下jQuery脚本将复选框转换为jQuery-UI按钮并设置要显示的图标。点击按钮时,它也会更改图标。它一切正常。然而,我似乎无法击中正确的语法来设置基于复选框的初始选中状态的初始图标。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>
编辑: 这是我最后的工作标记和脚本按如下accidentalgenius答案:
@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();
});
};
在上面的原始问题中放了我用过的最后一个脚本。 – daveywc 2012-01-30 06:06:12