jQuery来自非表单元素的serialize/serializeArray [英] jQuery serialize / serializeArray from an element that is not a form
问题描述
关于这是否可行,我还没有找到具体的答案,但似乎应该...
I haven't found a concrete answer as to whether this is possible, but it seems like it should be...
我想序列化div中包含的所有输入元素.我不能使用表单,因为它会嵌套在另一个表单中.然后,我将获取值并将其通过ajax发布.
I would like to serialize all the input elements contained in a div. I can't use a form, because it would be nested within another form. I would then get the values and post them via ajax.
这是我正在玩的jsFiddle示例:
Here is the jsFiddle example I am playing with:
如果我将根更改为a,它将按预期工作.
If I change the root to a it works as expected.
感谢您的帮助.
我从另一个问题修改了jsfiddle:
I've modified the jsfiddle from this other question:
https://stackoverflow.com/a/1186309/25020
推荐答案
您需要序列化容器内的所有输入,而不是实际容器本身.所以:
you need to serialize all the inputs inside your container, not the actual container itself. so:
$('div :input').serialize()
这篇关于jQuery来自非表单元素的serialize/serializeArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!