zoukankan      html  css  js  c++  java
  • form表单重置、清空方法记录

    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>
  • 相关阅读:
    修改NavigationBarItem的字体大小和颜色的使用方法
    iOS 大文件断点下载
    iOS 文件下载
    UITableView优化
    iOS 应用的生命周期
    iOS RunLoop简介
    iOS 线程间的通信 (GCD)
    iOS 多线程GCD的基本使用
    iOS 多线程GCD简介
    CSS--复习之旅(一)
  • 原文地址:https://www.cnblogs.com/ljblog/p/7735422.html
Copyright © 2011-2022 走看看