admin管理员组文章数量:1312741
Is there a way that I can have an image replace a checkbox, and when someone clicks on it, it selects it, and changes the image to another image like a "checked" image?
So essentially:
[heart-icon] Health and Fitness
user clicks on it
[check-icon] Health and Fitness
and now that area is selected
Is there a way that I can have an image replace a checkbox, and when someone clicks on it, it selects it, and changes the image to another image like a "checked" image?
So essentially:
[heart-icon] Health and Fitness
user clicks on it
[check-icon] Health and Fitness
and now that area is selected
Share Improve this question asked Feb 4, 2011 at 2:53 ParkerParker 111 gold badge1 silver badge2 bronze badges 1- You might want to check Help with a pure CSS Checkbox Image replacement?. – IsmailS Commented Aug 11, 2011 at 10:46
3 Answers
Reset to default 3There are definitely scripts/plugins available to do this. I've not used any of them so I can't remend one specifically, but here's an example:
http://www.itsalif.info/content/ezmark-jquery-checkbox-radiobutton-plugin
I would try this plugin: SimpleImageCheck http://www.jkdesign/imagecheck/
Code to customize the checkbox looks simple:
$('#checkbox').simpleImageCheck({
image: 'unchecked.png',
imageChecked: 'check.png'
afterCheck: function(isChecked) {
if (isChecked) {
// do something
}
}
});
No need of plugins nor JQuery:
<span onclick="changeCheck(this)">
<img src="http://www.clker./cliparts/e/q/p/N/s/G/checkbox-unchecked-md.png">
<img src="http://www.clker./cliparts/4/h/F/B/m/4/nxt-checkbox-checked-ok-md.png">
<input type="checkbox" name="chk">
</span>
<script>
function changeCheck(target)
{
chk = target.lastElementChild;
chk.checked = !chk.checked;
target.children[+ chk.checked].style.display = '';
target.children[1 - (+ chk.checked)].style.display = 'none';
}
function initCheck()
{
chk = document.getElementsByName('chk')[0];
chk.style.display = 'none';
chk.parentNode.children[1 - (+ chk.checked)].style.display = 'none';
}
initCheck();
</script>
本文标签: javascriptReplacing Checkbox with image and update onClick (possibly jQuery)Stack Overflow
版权声明:本文标题:javascript - Replacing Checkbox with image and update onClick (possibly jQuery?) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741894409a2403494.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论