我創建了一個div和一個按鈕。當點擊按鈕時,會在div中插入一組元素(包括1個選擇框和2個文本輸入)。用戶可以添加儘可能多的組,當他們完成鍵入所添加的所有組的數據時,他可以點擊保存按鈕,這會將來自每個組的值逐個放入JSON對象數組中。但是我被困在如何從每個組獲得價值的部分,所以請幫助,謝謝。 。如何創建動態控件並將其數據放入對象中?
爲div和添加組按鈕功能的代碼 - AddExtra()如下:
<div id="roomextra">
</div>
function AddExtra() {
$('#roomextra').append('<div class=extra>' +
'<select id="isInset">' +
'<option value="Inset">Inset</option>' +
'<option value="Offset">OffSet</option>' +
'</select>' +
'Length(m): <input type="text" id="insetLength">' +
'Width(m): <input type="text" id="insetWidth">' +
'Height(m): <input type="text" id="insetHeight">' +
'</div>');
}
function GetInsetOffSetArray (callBack) {
var roomIFSDetail = [{
"IsInset": '' ,
"Length": '' ,
"Width": '' ,
"Height": ''
}];
//should get all the value from each group element and write into the array.
callBack(roomIFSDetail);
}
完美!有用!非常感謝! – 2013-05-07 15:41:32
不客氣。 – Yatrix 2013-05-07 15:45:23