0
我在玉這樣一個隱藏的輸入字段:添加到HTML輸入數組
input(name='saintForm[quotes][]', type='hidden')
我想使用jQuery從動態無序列表添加到該數組,但不知道如何。這是我的失敗嘗試:
$('#form').on('submit', function(e){
e.preventDefault();
$('.quote').each(function (i){
var item = $(this).text().replace(' (x)','');
$("input[name='saintForm[quotes][]']").push(item);
});
this.submit();
});
你沒有數組,你有一個數組式的jQuery對象,它沒有'push'方法。你可能在尋找jQuery的'add()'方法,但不知道'item'是什麼,這是不可能知道的? – adeneo 2014-09-24 18:54:29
對不起,添加了該項目。我嘗試使用add(),但服務器上的結果仍顯示空白 - 引號:[''] – 2014-09-24 18:57:52
正如@adeneo提到的,您沒有數組。我認爲唯一的方法就是遍歷引號並逐個添加到輸入值。 – 2014-09-24 19:04:23