[英]create dynamic drop-downs using javascript
您好,我想使用JavaScript創建動態下拉菜單,但無法正常工作。
我的PHP代碼:
<input type="button" onclick="javascript:addRow();" value="Add Row" name="addRow"/>
我的JS代碼:
// This function is used to create dynamic form element
function addRow() {
var opt = document.createElement("option");
element = document.createElement("select");
element.setAttribute('id', 'focus');
element.options.add(opt);
}
PS:它沒有給出任何js控制台錯誤。
您沒有將元素添加到主體,因此它不會顯示
// This function is used to create dynamic form element
function addRow() {
var opt = document.createElement("option");
element = document.createElement("select");
element.setAttribute('id', 'focus');
element.options.add(opt);
document.body.appendChild(element);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.