0
如何獲得表格內的Bootstrap TouchSpin元素的值?我目前一無所獲,因爲我不相信它找到了這個元素。如何在表格內獲得TouchSpin的價值
的touchspin的創建和插入到表
var table = document.getElementById("createOrderTable");
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
row.id = 'row' + rowCount;
// TouchSpin element
var cell1 = row.insertCell(1);
var touchSpinID = 'touchspin' + rowCount;
cell1.innerHTML = "<input id='" + touchSpinID +"' type='text' value='1' name='" + touchSpinID +"'>";
cell1.id = 'cell' + touchSpinID;
//Init TouchSpin
$("input[name='" + touchSpinID +"']").TouchSpin({
verticalbuttons: true,
min: 0,
max: 100000000,
});
迭代通過表和獲取Touchspin,下面作品既不方法的價值。
var table = document.getElementById("createOrderTable");
var rowCount = table.rows.length;
var productArray = [];
for(i = 1; i < table.rows.length; i++){
var touchspinID = 'touchspin' + i;
var touchspinValue = 0;
cellID = 'cell' + touchspinID;
$(cellID).find(touchspinID).each(function(){
touchspinValue = this.val();
console.log(touchspinValue);
});
$("#createOrderTable tr").each(function() {
$('td', this).each(function() {
var value = $(this).find(touchspinID).val();
console.log(value);
})
})
}
你的html看起來像什麼?你能展示一個示例代碼片段嗎? – Yass