私は次の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答えあたりの通りです:あなたはsetCheckBoxImages()
を呼び出しているとき
@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