checkbox (复选框)取值
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> <script type="text/javascript"> $(function(){ $("#form").submit(function(){//表单提交:复选框取值 var obj=$(‘input:checkbox[name="aaa"]:checked‘); alert("长度: "+obj.length); obj.each(function(){ var s=$(this).val(); alert(s); }); return false; }); }); </script> <form method="post" action="" id="form"> <input type="checkbox" name="aaa" value="1" checked> <input type="checkbox" name="aaa" value="2"> <input type="checkbox" name="aaa" value="3"> <input type="submit"> </form>
radio(单选框)取值
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> <script type="text/javascript"> $(function(){ $("#form").submit(function(){//表单提交:单选框取值 var aaa=$(‘input:radio[name="aaa"]:checked‘).val(); alert(aaa); return false; }); }); </script> <form method="post" action="" id="form"> <input type="radio" name="aaa" value="1" checked> <input type="radio" name="aaa" value="2"> <input type="radio" name="aaa" value="3"> <input type="submit"> </form>
选择所有
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> <script type="text/javascript"> $(function(){ $("#check_all").click(function(){ var a=$(this)[0].checked; //alert( typeof a); var inputs = document.getElementsByTagName("input"); for(var i=0; i< inputs.length; i++){ if(inputs[i].type == "checkbox"){ inputs[i].checked = a; } } }); }); </script> <input type="checkbox" name="" id="check_all">选择所有 <hr> <input type="checkbox" name=""><br> <input type="checkbox" name=""><br> <input type="checkbox" name=""><br> <input type="checkbox" name=""><br> <input type="checkbox" name=""><br> <input type="checkbox" name=""><br> <input type="checkbox" name=""><br> <input type="checkbox" name=""><br> <input type="checkbox" name=""><br> <input type="checkbox" name=""><br>
时间: 2024-11-10 08:10:17