我有一些代碼在訂單確認屏幕上打印出客戶訂單。這是通過使用Javascript
來填充table
的信息。理想情況下,我想這樣做是JQuery
使用JQuery動態添加選擇框
這是我HTML
<!-- Order Confirmation Form -->
<form action="<?the_permalink()?>" method="post">
<div id="summary">
<table id="ordertable">
<tr><th>Product</th>
<th>Quantity</th>
<th>Bulk</th>
<th>Options</th>
</tr>
</table>
<!-- Comments Box -->
Comments<br/>
<textarea name="comments"></textarea><br/>
<input name="product_list" id="products_field" type="hidden" value="<?= isset($_POST['product_list'])?$_POST['product_list']:'' ?>">
Next Day Delivery <input type="checkbox" name="next-day-delivery" value="yes" />
<input type="submit" value="Confirm Order" class="confirmBtn"/>
</div>
</form>
這是我JS
//Reference to the order table
var ordertable = document.getElementById("ordertable");
//Loop through the Array and display in the table
for(var i = 0; i < productArray.length; i ++){
//This is the data to display
console.log("Order Item " + i);
console.log("StockCode: " + productArray[i].stockCode);
console.log("Quantity: " + productArray[i].quantity);
console.log("Bulk: " + productArray[i].bulk);
var row = ordertable.insertRow(i + 1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
cell1.innerHTML = productArray[i].stockCode;
cell2.innerHTML = productArray[i].quantity;
cell3.innerHTML = productArray[i].bulk;
cell4.innerHTML = "<input type='button' value='-' class='removeBtn'/><input type='button' value='+' class='addBtn'/><input type='button' value='Delete' class='deleteBtn'/>"
}
這是我的頁面的圖像,我似乎無法人物我怎樣才能將select
框添加到bulk
以下的單元格(以紅色標出)。這個想法如果bulk == true
顯示select
框else
不顯示任何東西。 (有些產品可以批量訂購。)
有沒有人有任何建議,我怎麼可能去實現呢?
在代碼中沒有'jQuery'的用法。請重新標記您的問題。 – melancia
@MelanciaUK也許它是在那裏表明,jQuery解決方案是受歡迎的..? –
@TJ是真的,我被告知我的代碼應該在'JQuery'中,顯然在上面它是'JS',但我對如何實現該解決方案的任何建議持開放態度。 – Javacadabra