Home  >  Article  >  Web Front-end  >  JS method to implement statistics on the number of selected check boxes and prompt confirmation and cancellation_javascript skills

JS method to implement statistics on the number of selected check boxes and prompt confirmation and cancellation_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:51:501032browse

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你确定选择删除过滤网址吗&#63;")){ 
   //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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn