我创建了动态表,单击按钮后在末尾添加行。在dropdown list
我想要包含数据库值的一列中。
这是我创建表的方式:
<script type="text/javascript">
function createRow() {
var row = document.createElement('tr'); // create row node
var col = document.createElement('td'); // create column node
var col2 = document.createElement('td'); // create secondcolumn node
var col3 = document.createElement('td'); // create next node
var col4 = document.createElement('td'); // create next column node
var col5 = document.createElement('td'); // create next column node
row.appendChild(col); // append first column to row
row.appendChild(col2); // append second column to row
row.appendChild(col3); // append next column to row
row.appendChild(col4); // append next column to row
row.appendChild(col5); // append next column to row
col.innerHTML = '<select name="search-alias-0017" id="hasla" title="Search in">' +
'<option value="aps" selected="selected">--Wybierz z listy--</option> ' +
'<option value="stripbooks">opcja</option>' +
'<option value="popular">Haslo2</option>' +
'</select>';
c//rest columns
var table = document.getElementById("tableToModify"); // find table to append to
table.appendChild(row); // append row to table
}
</script>
现在我有drop down list
两个选择。我修改了它并从我的数据库中加载了一些变量,我希望将这些值放入<option>
标签中。其实我的JS
样子:
<script type="text/javascript">
function createRow() {
<? $q = "select name from vulnerability";
$result = $db - > query($q) - > fetchall(); ?>
var options = '';
options += '<select name="search-alias-0017" id="hasla" title="Search in">';
for (var i = 0; i < <? echo $result(sizeof($result); ?> ; i++) {
options += '< option > <? echo $result[i]['name ']; ?> < /option>';
}
options+='</select > ';
var row = document.createElement('tr'); // create row node
var col = document.createElement('td'); // create column node
var col2 = document.createElement('td'); // create secondcolumn node
var col3 = document.createElement('td'); // create next node
var col4 = document.createElement('td'); // create next column node
var col5 = document.createElement('td'); // create next column node
row.appendChild(col); // append first column to row
row.appendChild(col2); // append second column to row
row.appendChild(col3); // append next column to row
row.appendChild(col4); // append next column to row
row.appendChild(col5); // append next column to row
col.innerHTML = options;
c//rest columns
var table = document.getElementById("tableToModify"); // find table to append to
table.appendChild(row); // append row to table
}
</script>
但不知何故我的代码不起作用......有人可以给我一个提示我做错了什么吗?