jQuery只获取可见字段的表单数据 [英] jQuery get form data for only visible fields

查看:24
本文介绍了jQuery只获取可见字段的表单数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 form 中,我得到了可见和不可见 (display:none) 元素.我只需要获取可见字段的表单数据.我正在使用以下代码收集数据:

In my form I got both visible and non-visible (display:none) elements. I need to get form data for only visible fields. I am collecting the data with the following code:

var formData = $('#myForm')
               .serializeArray()
               .reduce(function(obj, item) {   
                    //need to process only visible fields somewhere here                     
                    obj[item.name] = item.value;
                    return obj;
                }, {});

我知道禁用输入的 name 属性,但在收集数据后,我想为所有字段返回此属性.欢迎任何想法.谢谢.

I know about disabling the name propery of the input, but after the data is collected, I would like to return this property for all fields back. Any ideas would be welcome. Thank you.

推荐答案

$("#myForm :visible").each(function(){
  console.log(this);
}); 

这篇关于jQuery只获取可见字段的表单数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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