gpt4 book ai didi

jquery如何获取表单元素类型、名称和值

转载 作者:行者123 更新时间:2023-12-03 22:12:29 26 4
gpt4 key购买 nike

我知道我可以使用

获取名称/值关系
$(#form).serializeArray();

但是有没有一种方法可以通过一次调用获取完整的 enchilada、类型、名称和值?

最佳答案

使用$("form:input")

根据 docs :

Description: Selects all input, textarea, select and button elements.

现在回答你的问题,

there a way to get the whole enchilada, type, name and value with one call?

如果您只想循环浏览项目,

$("form :input").each(function(index, elm){
//Do something amazing...
});

但是如果你想返回某种结构,你可以使用.map()

var items = $("form :input").map(function(index, elm) {
return {name: elm.name, type:elm.type, value: $(elm).val()};
});

或者如果您只是想获取元素

$("form :input").get()


<强> Example of this on jsfiddle

关于jquery如何获取表单元素类型、名称和值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5666445/

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