請問 javascript 動態產生下拉式選單

edited 十月 2013 in Javascript
我有一個資料庫內容為
test1 test2 <==欄位
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
11 11

請問一下我該如何把資料庫的內容放到<option value="1">1</option>

下面是寫死的 是否可變成我在資料庫新增數值後讓夏拉式選單去連資料庫取值
<script>
function add_new_data() {

var num = document.getElementById("mytable").rows.length;
var Tr = document.getElementById("mytable").insertRow(num);
Td = Tr.insertCell(Tr.cells.length);
Td.innerHTML = '<select name="machine1[]"><option value="1">1</option><option value="2">2</option><option value="3>3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option></select>';
}

function remove_data() {
var num = document.getElementById("mytable").rows.length;
if(num >2)
document.getElementById("mytable").deleteRow(-1);
}
</script>
<form id="fomr1" name="fomr1" action="" method="post">

<input type="button" value="增加" onclick="add_new_data()">

<input type="button" value="減少" onclick="remove_data()"><br />

<table id="mytable" width="580" border="1" align="center" cellpadding="0" cellspacing="0" >
<tr>
<td width="150" class="td01">SELECT</td>
</tr>
<tr>

</tr>
</table>

<input type="submit" value="送出">
</form>

原始討論: http://twpug.net/x/modules/newbb/viewtopic.php?topic_id=7255

評論

Sign In or Register to comment.