我想做一個複選框的形式,有鼠標懸停在圖像和檢查圖像功能與jQuery。複選框圖像形式與jQuery
我成功地完成了每個功能,但沒有一起工作。
這裏是我的html表單。
<label for="w_interest">
<img src="/images/account/w_select.png_img"/ style='cursor:pointer;'>
<input name="w_interest" type="checkbox" id="w_interest" style="display:none">
</label>
這裏是jquery的
$(document).ready(function() {
$('#w_interest').hover(
function() {
$('img', this).attr('src', '/images/account/w_select_hover.png');
},
function() {
$('img', this).attr('src', '/images/account/w_select.png');
}
);
$("#w_interest").change(function() {
if(this.checked) {
$(this).prev().attr("src", "/images/account/w_select_checked.png");
} else {
$(this).prev().attr("src", "/images/account/w_select.png");
}
});
});
當用戶在圖像上移動圖像上的鼠標指針,圖像變化到鼠標。
當他或她點擊圖像時,它會更改爲選中的圖像。 (當然,它會檢查複選框)
你能幫我把這兩個功能結合起來嗎?
哪一部分不工作?你能提供一個鏈接或jsfiddle例子嗎? – rgin 2012-04-13 06:47:32