html中checkbox的格式如下:
<div id='jfxz'> <div><input type="checkbox" /><span>1</span></div> <div><input type="checkbox" /><span>2</span></div> <div><input type="checkbox" /><span>3</span></div> <div><input type="checkbox" /><span>4</span></div> <div><input type="checkbox" /><span>5</span></div> <div><input type="checkbox" /><span>6</span></div> </div>
html
function checkboxControl(){//$(function(){$("#jfxz").find(":checkbox").each(function(){$(this).click(function(){$(this).attr('checked',true);//被选中的置为true$("#jfxz").find(":checkbox").not($(this)).each(function(){//被选中的之外的元素,遍历置为false$(this).attr('checked',false);});});});//}); }
js
若checkbox仅为同一div下的多个同济checkbox,则可用:
$(":checkbox").click(function(){ //设置当前选中checkbox的状态为checked $(this).attr("checked",true); $(this).siblings().attr("checked",false); //设置当前选中的checkbox同级(兄弟级)其他checkbox状态为未选中 });
js
参考:
https://blog.csdn.net/siyi_blog/article/details/80905904