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

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

问题描述

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

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天全站免登陆