我需要在网页上添加一个下拉列表.通常HTML代码是这样的;
如何使用JavaScript创建上面的元素.在我创建此下拉列表后.我需要在按钮后添加它.
var button = document.getElementById("button1");
我已经得到了按钮元素.此外,单击该按钮时,我想知道人们在下拉列表中选择了哪个选项.我怎么能用JavaScript做到这一点.
我试试这个
var select = document.createElement("select"); select.id = "wayToCalculate"; //select.name="au_1_sel"; //select.class=class="searchw8"; var option1 = document.createElement("option"); option1.value="1"; option1.selected=""; option1.innerHTML= "1"; var option2 = document.createElement("option"); option2.value="2"; option2.innerHTML= "2"; var option3 = document.createElement("option"); option3.value="3"; option3.innerHTML= "3"; select.addChild(option1); select.addChild(option2); select.addChild(option3); $(select).insertAfter(button);
但是当涉及到这一点.select.addChild(选项1);
chrome浏览器给我一个错误.
Uncaught TypeError: undefined is not a function
似乎addChild在这里不起作用.