使用jQuery清除表单字段 [英] Clear form fields with jQuery

查看:119
本文介绍了使用jQuery清除表单字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想清除表单中的所有输入和textarea字段。当使用带有 reset 类的输入按钮时,它的工作方式如下所示:

  $(。reset)。bind(click,function(){
$(input [type = text],textarea)。val();
}) ;

这将清除页面上的所有字段,而不仅仅是表单中的字段。我的选择器对于只有实际的重置按钮所在的表单而言会如何?

> $(。reset)。click(function(){
$(this).closest('form')。find(input [type = text],textarea)。val() ;
});


I want to clear all input and textarea fields in a form. It works like the following when using an input button with the reset class:

$(".reset").bind("click", function() {
  $("input[type=text], textarea").val("");
});

This will clear all fields on the page, not just the ones from the form. How would my selector look like for just the form the actual reset button lives in?

解决方案

$(".reset").click(function() {
    $(this).closest('form').find("input[type=text], textarea").val("");
});

这篇关于使用jQuery清除表单字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆