我有一个按钮,当按下它时,它会创建一个新行。该行由选择,文本和单元格组成。我的选择框在创建时有一个默认选项' t'。如何在不使用html的情况下列出多个选项?
我尝试创建一个新的textnode,当我为两个选项执行appendChild时,我将它们放在同一行上。我需要第二个变量' u'成为一个全新的选择。任何帮助都非常感谢。
HTML
<button onclick="AddRow()"></button>
的Javascript
function addRow(){
var optionObject = {};
var table=document.getElementById('table2'),tr,input,row,cell
tr=document.createElement('tr');
tr.setAttribute("class","rows");
tr.id = "AddedRow";
field = document.createElement("select");// this is where the select box is
var z = document.createElement("option"); //this is to create an option for the select box
z.setAttribute("value", "Choose"); // this is to give it a default value
var t = document.createTextNode("Select a Current Job");// this is to give it a default field name
var u = document.createTextNode("Select yoyo");// this is to give it a default field name
z.appendChild(t);// append the default field name to the option
z.appendChild(u);// append the default field name to the option
field.appendChild(z);// append the option to the select box
field.setAttribute("id","jobSelector");
//field.setAttribute("class","celltimes5a");
field.setAttribute("class","celltimesSelect");
var jobCol=document.createElement('td');
jobCol.setAttribute("class","celltimes5c");
tr.appendChild(field);
tr.appendChild(jobCol);
td=document.createElement('td');
td.setAttribute("class",'celltimes4c');
td.id = "row14total";
tr.appendChild(td);
table.appendChild(tr);
}
答案 0 :(得分:0)
需要创建另一个新选项并将其追加
var z = document.createElement("option"); //this is to create an option for the select box
z.setAttribute("value", "Choose"); // this is to give it a default value
var w = document.createElement("option"); //this is to create an option for the select box
w.setAttribute("value", "Choose"); // this is to give it a default value
var t = document.createTextNode("Select a Current Job");// this is to give it a default field name
var u = document.createTextNode("Select yoyo");// this is to give it a default field name
z.appendChild(t);// append the default field name to the option
w.appendChild(u);// append the default field name to the option
field.appendChild(z);// append the option to the select box
field.appendChild(w);// append the option to the select box