我认为这可能是您正在寻找的。这将在您的设备表中动态添加一个新行,并创建一个新的下拉列表,该下拉列表已被填充。
<!DOCTYPE html>
<html>
<head>
<title>Equipment</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type="text/javascript">
var rows = 0;
function addMoreEquipment() {
rows++;
var options = [{ name: "Item 1", value: "1" }, { name: "Item 2", value: "2" }, { name: "Item 3", value: "3" }];
var row = $("<tr id='row"+ rows +"'><td><select id='equipment" + rows + "'></select></td><td><a href='#' onclick='removeRow(\"row" + rows + "\")'>Remove</a></td></tr>")
$("#equipment").append(row);
for (var i = 0; i < options.length; i++)
$("#equipment" + rows).append(new Option(options[i].name, options[i].value));
}
function removeRow(id) {
$("#" + id).remove();
}
$(document).ready(function() {
addMoreEquipment();
});
</script>
</head>
<body>
<form>
<table border="1" id="equipment">
<tr>
<td>Kod Peralatan</td>
<td>Nama Peralatan</td>
</tr>
</table>
<div style="text-align: right">
<input type="button" onclick="addMoreEquipment()" value="Add Row">
</div>
</form>
</body>
</html>
你可以在这里查看更新的 JS Fiddle:http:
//jsfiddle.net/b3gYk/1/