myform 是form的id属性值
1.调用reset()方法
1 function fomrReset() 2 { 3 document.getElementById("myform").reset(); 4 }
2. 逐个清空input、select值
1 function resetAll() { 2 $("#myform").find(\'input[type=text],select,input[type=hidden]\').each(function() { 3 $(this).val(\'\'); 4 }); 5 }
3.排除法清空form表单
1 <!DOCTYPE html> 2 <html> 3 4 <head> 5 <meta charset="UTF-8"> 6 <title>form表单重置</title> 7 <script src="login/js/jquery-1.4.2.min.js"></script> 8 </head> 9 10 <body> 11 <form action="" method="post" id="myform"> 12 <label for="name">姓名:</label> 13 <input type="text" name="name" id="name" value="" placeholder="请输入名字" /> 14 <label>性别:</label> 15 <input type="radio" name="sex" checked value="" />男 16 <input type="radio" name="sex" value="" />女 17 </form> 18 <input type="button" name="" value="重置" onclick="formReset()" /> 19 <script type="text/javascript"> 20 function formReset() { 21 $(\':input\', \'#myform\') 22 .not(\':button, :submit, :reset, :hidden,:radio\') // 去除不需要重置的input类型 23 .val(\'\') 24 .removeAttr(\'checked\') 25 .removeAttr(\'selected\'); 26 } 27 </script> 28 </body> 29 30 </html>