我知道我可以使用
获取名称/值关系$(#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()
关于jquery如何获取表单元素类型、名称和值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5666445/