我想創建一個使用與複選框元素相關聯的標籤並隱藏(顯示:無)複選框的自定義設計複選框。點擊標籤不檢查複選框,如果隱藏時使用IE 7或8
在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
我認爲這種情況在Firefox過,但我不知道。 – Inkbug 2012-07-18 14:06:11
不是在OSX的最新版本的FF上,不是在Windows上試過。 – Tom 2012-07-18 14:16:38