我想做一個複選框的形式,有鼠標懸停在圖像和檢查圖像功能與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() {
$('#img').hover(
function() {
$(this).attr('src', '/images/account/ws_145_hover.png');
},
function() {
$(this).attr('src', '/images/account/ws_145.png');
}
);
$("#img").click(function() {
if(1) {
$(this).attr("src", "/images/account/ws_145_checked.png");
$("#w_interest").val("0");
} else {
$(this).attr("src", "/images/account/ws_145.png");
$("#w_interest").val("1");
}
});
});
當我點擊圖像,它將改爲檢查到的圖像。但是,當我將鼠標移出時,它會更改爲原始圖像。我想確保它保持在檢查圖像。
我想確保它檢查複選框的輸入。
如果用戶再次單擊選中的圖像,它將取消選擇複選框輸入。
你能幫我解決jquery問題嗎?
真棒!謝謝!! – james 2012-04-16 08:22:01