我想做一个复选框的形式,有鼠标悬停在图像和检查图像功能与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