wqsbk

表单一般都有重置功能,在重置表单时需要将各个输入框中的值清空,如果输入框比较多,一个一个清空会比较麻烦,使用jquery的方法直接将表单中的所有输入框全部清空,首先给出一个form表单:

<form id="form">
    <input type="text" value="123" /><br />
    <input type="radio" name="radio" value="1" checked="checked"/>
    <input type ="radio" name="radio" value="2" />
    <input type="file" /><br />
    <input type="checkbox" name="checkbox" value="1" checked="checked"/>
    <input type="checkbox" name="checkbox" value="2" /><br />
    <input type="submit" value="提交"/>
    <input type="button" id="reset" value="重置" />
</form>

需要在页面上引入jquery:

<script type="text/javascript" src="js/jquery.min.js" ></script>

重置表单方法:

<script>
    $(function(){
        $("#reset").click(function(){
            $(\':input\',\'#form\')
            .not(\':button,:submit,:reset,:hidden\')
            .val(\'\')
            .removeAttr(\'checked\')
            .removeAttr(\'selected\');
        });
    });
</script>

 

分类:

技术点:

相关文章:

  • 2022-02-13
  • 2021-12-06
  • 2022-01-27
  • 2022-12-23
  • 2021-11-24
  • 2021-12-10
猜你喜欢
  • 2021-12-22
  • 2021-12-06
  • 2021-12-04
  • 2022-12-23
  • 2021-06-17
  • 2021-12-06
  • 2021-12-28
相关资源
相似解决方案