Html中使用自定义图片来实现checkbox表现的方法
2016/12/29 13:55:21来源:互联网
假如必要使用图片来实现checkbox的使用,可以使用来实现,实现原理是将label表签代替checkbox的表现,将checkbox的display设置为none,在label标签中使用要表现的图片img,再使用js函数去控制图片的选中与否的切换。
javascript Code复制内容到剪贴板
<label for="agree" >
<img class="checkbox" alt="选中" src="../img/checked.png" id="checkimg" onclick="checkclick();">
</label>
<input type="checkbox" style="display:none" id="agree" checked="checked">
<script>
function checkclick(){
var checkimg = document.getElementById("checkimg");
if($("#agree").is(':checked') ){
$("#agree").attr("checked","unchecked");
checkimg.src="../img/unchecked.png";
checkimg.alt="未选";
} else{
$("#agree").attr("checked","checked");
checkimg.src="../img/checked.png";
checkimg.alt="选中";
}
}
</script>以上就是小编为大家带来的Html中使用自定义图片来实现checkbox表现的方法悉数内容了,盼望大家多多支持图趣网~
免责声明:本站文章系图趣网整理发布,如需转载,请注明出处,素材资料仅供个人学习与参考,请勿用于商业用途!
本文地址:http://www.tuquu.com/tutorial/wd3338.html
本文地址:http://www.tuquu.com/tutorial/wd3338.html
这些是最新的
最热门的教程

