如何使用jquery在exisitng数据中添加更多数据 - 或者只是简单的javascript?
fd = {
name : file_data.name,
size : file_data.size
};
// And others.
$("form").find('input[type=hidden]').each(function(){
$(fd).data(this.name, this.value);
});
我得到了这个奇怪的结果,
Array
(
[name] => Dangerous Man.mp3
[size] => 11912748
[jQuery1910560199169432603] => Array
(
[toJSON] => undefined
[data] => Array
(
[article_id] =>
[category_id] => 15
[user_id] => 1
[max_upload_filesize] => 3
[method] => upload
[required[category_id] => Category ID
)
)
)
但是我追求这个结果,
Array
(
[name] => Dangerous Man.mp3
[size] => 11912748
[article_id] => 1
[category_id] => 15
[user_id] => 1
[max_upload_filesize] => 3
[method] => upload
[required[category_id] => Category ID
)
任何想法?
答案 0 :(得分:1)
只需将属性添加到对象
即可$("form").find('input[type=hidden]').each(function(){
fd[this.name] = this.value;
});
答案 1 :(得分:1)
您只能将Element,NodeList,selector或函数传递给$ function,而不是Object。 你应该这样做:
fb[ this.name ] = this.value;
而不是
$(fd).data(this.name, this.value);