jQuery .serialize() 不是函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12815951/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery .serialize() not a function
提问by a1337q
Why does this not work?
为什么这不起作用?
var me = $('#'+id);
var content = $(me).find('input').val().serialize();
I get TypeError: $(me).find("input").val().serialize is not a function
我得到 TypeError: $(me).find("input").val().serialize is not a function
回答by Denys Séguret
Because $(me).find('input').val()
is a string and not a jQuery object, it doesn't have the serializefunction.
因为$(me).find('input').val()
是字符串而不是 jQuery 对象,所以它没有序列化功能。
If you want to serialize the input (with its value), use $(me).find('input').serialize();
如果要序列化输入(及其值),请使用 $(me).find('input').serialize();
But be sure to really need it : this function is rarely useful for just one input (we generally use it for forms). If you just want the value, use $(me).find('input').val()
and if you're debugging and want to inspect the element, use console.log($(me))
and open the console of your browser.
但一定要真的需要它:这个函数很少对一个输入有用(我们通常将它用于表单)。如果您只想要该值,请使用$(me).find('input').val()
;如果您正在调试并想要检查元素,请使用console.log($(me))
并打开浏览器的控制台。
回答by Anoop
You can use .serialize()
on form directly.
you can serialize form as below
您可以.serialize()
直接在表单上使用。您可以将表单序列化如下
var serializeData = $('form').serialize();