获取checkbox的value值

获取checkbox的value值

效果:
获取checkbox的value值_第1张图片

源码:

  
<html lang="en">  
<head> 
	<meta charset="utf-8">
	<script src="./ceshi/jquery-1.12.2.js">script>
  <meta charset="UTF-8">
  <title>获取checkbox的value值title> 
 head>
 
 <body>
   <input onchange="freshArea()" id='chk1' name='checkbox'  type='checkbox' value='A'/>AA
   <input onchange="freshArea()" id='chk2' name='chk'  type='checkbox' value='B'/>BB
   <input onchange="freshArea()" id='chk3' name='chk'  type='checkbox' value='C'/>CC
   <input onchange="freshArea()" id='chk4' name='chk'  type='checkbox' value='D'/>DD
   <input onchange="freshArea()" id='chk5' name='chk'  type='checkbox' value='E'/>EE
   <input onchange="freshArea()" id='chk6' name='chk'  type='checkbox' value='F'/>FF

   <textarea id="view" value="btn">textarea>
 body>
 
 <script>
  function freshArea(){
         var obj = document.getElementsByName('chk');
         var obq = document.getElementsByName('checkbox');
         var s = '';
         var c = '';
         for (var i = 0; i < obj.length; i++) {
             if (obj[i].checked) s += obj[i].value;
        }
        for (var i = 0; i < obq.length; i++) {
             if (obq[i].checked) c += obq[i].value;
        }
        // alert(s == '' ? '你还没有选择任何内容!' : s);
        // console.log(s == '' ? '你还没有选择任何内容!' : s);
        var content = (c == '' ? '这是第一组checkbox' : c) + (s == '' ? '这是第二组checkbox' : s);
		var view = document.getElementById("view");
        view.value =content; 
    }
script>
html>

你可能感兴趣的:(网页开发)