【发布时间】:2014-11-11 12:30:33
【问题描述】:
提交表单“未定义不是第 21 行中的函数”时,此代码给我一个错误,我不知道为什么
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name] !== undefined) {
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;
};
$("form[name=dForm]").submit(function(ev){
ev.preventDefault();
var data = $(this).serializeObject();
data.push({name:"bonjour",value:bonjour});
// do something here ...
})
或者它必须是一个数组而不是一个对象?
【问题讨论】:
-
看起来 data 是一个对象而不是数组..
-
push 是一个 Javascipt 函数。不是jQuery的
-
是的,我不知道如何在数组中制作它。因为我有多个具有相同选择器的表单
标签: javascript jquery arrays ajax object