如何使用jQuery重置特定的表单字段 [英] How to reset a particular form field using jQuery

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

问题描述

我想知道如何使用jQuery重置特定表单字段。

I want to know how to reset a particular form field using jQuery.

我正在使用以下函数:

function resetForm(id) {
    $('#'+id).each(function(){
        this.reset();
    });
}

但重置所有字段。有没有办法使用jQuery或JavaScript重置特定字段?我想只重置一个特定字段。

but it is resetting all the fields. Is there any way to reset specific fields using jQuery or JavaScript? I want to reset only a particular field.

推荐答案

function resetForm(id) {
    $('#' + id).val(function() {
        return this.defaultValue;
    });
}

不使用id的示例:

http://jsfiddle.net/vYWdm/

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

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