复选框CheckBox的使用

js代码全选

<script type="text/javascript"> function checkAllBox(obj){ var answer= document.getElementsByName("checkbox"); if(obj.checked==true){ for(var i=0;i<answer.length;i++){ answer[i].checked = true; } }else{ for(var i=0;i<answer.length;i++){ answer[i].checked = false; } } } </script>

js代码 判断哪个被选中

<script type="text/javascript"> function xuanzhong(obj){ var answer= document.getElementsByName("checkbox"); for(var i=0;i<answer.length;i++){ if( answer[i].checked){ var ans=answer[i].value; } } <script> 

form表单

<form action="#">
<input type="checkbox" onclick="checkAllBox(this);" value="全选"/>
<p onclick="xuanzhong(this);">选中的值</p>
<table cellpadding="0" cellspacing="0" id="table" width="800px" height="50">
        <tr>
            <th style="text-align: center" nowrap height="44">选择</th>
            <th style="text-align: center" nowrap height="44">商品类型名称</th>
            <th style="text-align: center" nowrap height="44">商品类型内容</th>
            <th style="text-align: center" nowrap height="44">排序</th>

        </tr>
        <tr>
        <input type="checkbox" name="checkbox" value="1"/></td>
        <td align="center">111</td>
        <td align="center">222</td>
        <td align="center">222</td>
        </tr>
        <tr>
        <input type="checkbox" name="checkbox" value="2"/></td>
        <td align="center">111</td>
        <td align="center">222</td>
        <td align="center">222</td>
        </tr>
        <tr>
        <input type="checkbox" name="checkbox" value="3"/></td>
        <td align="center">111</td>
        <td align="center">222</td>
        <td align="center">222</td>
        </tr>
<table> 
</form> 

你可能感兴趣的:(form)