我想使用jquery获取所有文本框值,并在onchange事件上将它们全部设置为null [英] I want to get all textbox values using jquery and make them all null on onchange event

查看:103
本文介绍了我想使用jquery获取所有文本框值,并在onchange事件上将它们全部设置为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用jQuery获取表单中的所有值 并希望将所有这些值设置为null.

I'm trying to get all values within a form using jQuery and want to set all those as a value null.

现在我也有文字和隐藏字段.

Now I have text also and hidden fields also.

<input id="MYNAME_04cd1197-7147-4b82-9b0a-c44846405150" 
       type="text" 
       value="MyName"/>

<input id="MYID_12cd1112-7147-4b82-9b12-c412846125112" 
       type="hidden" 
       value="f208b514-133b-4d6d-8299-f5f002e131a0"/>

有很多这样的文本框.

我可以知道获取所有这些文本框并将null设置为[type="text]"的值的语法是什么 和00000000-0000-0000-0000-000000000000[type=hidden]输入.

May I know what is the syntax to get all these textboxes and set null as value to [type="text]" and 00000000-0000-0000-0000-000000000000 to [type=hidden] inputs.

我尝试了类似的方法:

  function resetAllValues() {
        debugger;
        $('#TransactionGrid').find("input:text").each(function (index) { });
    }

推荐答案

您可以执行以下操作:

$('form > input').val('');

但是每个人都会以不同的方式告诉您. 您应该知道的是:

But this everyone will tell to you in different ways. What you should know is:

如果要从表单中获取所有值(如您所评论的),则您的html元素必须具有名称属性.例如,您不能使用$('#frm1').serialize().

Your html element must have the attribute NAME, if you want to get all the values from the form(as you commented). You can't use $('#frm1').serialize() for example.

这篇关于我想使用jquery获取所有文本框值,并在onchange事件上将它们全部设置为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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