jQuery .serializeObject不是一个函数 - 只在Firefox中 [英] jQuery .serializeObject is not a function - only in Firefox
问题描述
我正在使用jQuery,特别是这个函数。
$ b $ p $(#postStatus)。serializeObject(); $ b
它在Chrome和Safari中绝对正常,但是当我在Firefox中使用它时,它不起作用。我用Firebug来看看它给了什么错误,我得到这个
$(#postStatus)。serializeObject不是为什么Firefox的这个函数不能工作?
更新。 ..
哦,是的,我完全忘了这不是核心功能。我记得我搜索了一种方式来序列化一个表单,并找到了这个解决方案;
$。fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$ .each(a,function(){
if(o [this.name]){
if(!o [this.name] .push){
o [ this.name] = [o [this.name]];
}
o [this.name] .push(this.value ||'');
} else {
o [this.name] = this.value ||'';
}
});
return o;
};
通过将上面的函数放置在JS文件的顶部,我设法解决了这个问题。感谢您的帮助。
AFAIK jQuery没有函数定义为 或者您可以将javascript放在页面底部。 I'm using jQuery, and specifically this function It works absolutely fine in Chrome and Safari, but when I do it in Firefox it doesn't work. I used Firebug to see what error it was giving, and i'm getting this Why doesn't this function work in Firefox? UPDATE... Oh yes, I completely forgot that it's not a core function. I remember that I searched a way to serialize a form and found this solution; I've managed to fix this issue by placing the function above at the top of the JS file. Thanks for your help guys. AFAIK jQuery has no function defined as or you can place the javascript at the bottom of the page. 这篇关于jQuery .serializeObject不是一个函数 - 只在Firefox中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! serializeObject $ c $在它的核心。可能你正在使用一个插件,并且它在Firefox中有问题,所以它可以安全地假设你的脚本包含是正确的,试着把你的代码包装在ready处理程序中。
< pre $ $(function(e){
$(#postStatus)。serializeObject();
});
$("#postStatus").serializeObject();
$("#postStatus").serializeObject is not a function
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
serializeObject
in its core. Probably you are using a plugin, and that its problematic in Firefox only so its safe to assume that your script inclusion is in proper order, try wrapping up your code in the ready handler $(function(e){
$("#postStatus").serializeObject();
});