gpt4 book ai didi

javascript - jQuery 仅获取可见字段的表单数据

转载 作者:太空宇宙 更新时间:2023-11-04 15:33:55 25 4
gpt4 key购买 nike

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

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

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

最佳答案

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

关于javascript - jQuery 仅获取可见字段的表单数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44568019/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com