Home >Web Front-end >JS Tutorial >JS method to implement statistics on the number of selected check boxes and prompt confirmation and cancellation_javascript skills
The example in this article describes how to implement JS to count the number of selected check boxes and prompt confirmation and cancellation. Share it with everyone for your reference. The specific implementation method is as follows:
The javascript part is as follows:
<script type="text/javascript"> function yesno() { var inputs = document.getElementsByName("ck[]"); var checked_counts = 0; for(var i=0;i<inputs.length;i++){ if(inputs[i].checked){checked_counts++; } } if(confirm("你已选择了 " + checked_counts + " 个网址,\n你确定选择删除过滤网址吗?")){ //return true; ShowDiv('MyDiv','fade'); }else{ return false; } } </script>
The html page part is as follows:
<form id="form1" name="form1" method="post" action=""> <input type="checkbox" name="ck[]" id="ck[]" value="{$vo.id}" onclick="javascript:chkRow(this);"> <input type="checkbox" name="ck[]" id="ck[]" value="{$vo.id}" onclick="javascript:chkRow(this);"> <input type="checkbox" name="ck[]" id="ck[]" value="{$vo.id}" onclick="javascript:chkRow(this);"> <input type="checkbox" name="ck[]" id="ck[]" value="{$vo.id}" onclick="javascript:chkRow(this);"> <input type="checkbox" name="ck[]" id="ck[]" value="{$vo.id}" onclick="javascript:chkRow(this);"> <input type="checkbox" name="ck[]" id="ck[]" value="{$vo.id}" onclick="javascript:chkRow(this);"> <input type="checkbox" name="ck[]" id="ck[]" value="{$vo.id}" onclick="javascript:chkRow(this);"> <input type="checkbox" name="ck[]" id="ck[]" value="{$vo.id}" onclick="javascript:chkRow(this);"> <input type="checkbox" name="ck[]" id="ck[]" value="{$vo.id}" onclick="javascript:chkRow(this);"> <input type="checkbox" name="ck[]" id="ck[]" value="{$vo.id}" onclick="javascript:chkRow(this);"> <input type="submit" name="submit" id="submit" class="subbut" onclick="return yesno();" value="选择删除信息"> </form>
I hope this article will be helpful to everyone’s JavaScript programming design.