function dadosFormularios() {
var dadosFormulario = {};
var iterador = countForms;
var i = 0;
while (i < iterador) {
dadosFormulario[i] = {};
dadosFormulario[i]['a'] = $('#field\\[' + i + '\\]\\[a\\]').val();
dadosFormulario[i]['b'] = $('#field\\[' + i + '\\]\\[b\\]').val();
//alert(dadosFormulario[i]['a']);
//alert(dadosFormulario[i]['b']);
i++;
}
var qstring = '';
var tmp_qstring = [];
var temp1, temp2;
var aux_i = i + 1;
alert(aux_i);
for (var j = 0; j < aux_i; j++) {
temp1 = dadosFormulario[j]['a'];
alert(temp1);
temp2 = dadosFormulario[j]['b'];
//alert(temp1);
tmp_qstring[j] = 'a' + j + '=' + temp1 + '&' + 'b' + j + '=' + temp2;
}
qstring = tmp_qstring.join('&');
alert(qstring);
window.location = 'dup1.php?' + qstring;
}
當我點擊一個按鈕時,我調用上述函數,現在我試圖將對象數組的數據發送到另一個頁面,如代碼中所示。Jquery Javascript Property undefined
我的問題是,我得到當我設置dadosFormulario[j]['a'];
或dadosFormulario[j]['b'];
到VAR或直接在tmp_qstring
即tmp_qstring[j]=dadosFormulario[j]['b'];
設置它們的麻煩。在Chrome控制檯我得到的錯誤:
Uncaught TypeError: Cannot read property 'a' of undefined
「countForms」的定義在哪裏? – 2012-07-13 14:14:29
在Chrome的控制檯中,您會看到一個暫停按鈕。它告訴瀏覽器打破JS異常。按兩下進入「未捕獲異常中斷」模式。然後,瀏覽器會在發生異常時暫停。此時,您可以按照異常消息上的代碼:行鏈接,然後將鼠標懸停在局部變量上查看它們的值。如果這沒有幫助,可以用一些'console.log'語句來支持你的代碼以打印出變量的值。你很快就會看到出了什麼問題。 – 2012-07-13 14:36:41
解決了。感謝:P – user1511579 2012-07-13 14:39:37