チェックボックス要素に関連付けられたラベルを使用してカスタムデザインのチェックボックスを作成し、チェックボックスを非表示 (表示: なし) にしようとしています。
これは、ラベルをクリック可能にするためにチェックボックスを表示する必要がある IE を除くすべてのブラウザーで正常に機能します。
これが私のコードです...
HTML
<input type="checkbox" id="myCheck" />
CSS
label.checkbox {
border:1px solid #666;
width:25px;
height:23px;
display:block;
}
jquery
$("input[type=checkbox]").each(function() {
$(this).hide().before('<label for="' + $(this).attr("id") + '" class="checkbox"></label>');
});
$("input[type=checkbox]").live('change', function() {
if ($(this).prop('checked') == true) {
$('label[for=' + $(this).attr("id") + ']').html("X")
} else {
$('label[for=' + $(this).attr("id") + ']').html("")
}
});
またはjsfiddle