我试图填充HTML与JavaScript数组选择,你们可以帮我做这个工作,下面是我的代码填充HTML与JavaScript数组
外部JavaScript(我发现这个代码在互联网上的某个地方)
function setRuleName()
{ var myCars=new Array("Saab","Volvo","BMW");
var sel = document.getElementById("dropping") // find the drop down
for (var i in myCars)
{ // loop through all elements
var opt = document.createElement("option"); // Create the new element
opt.value = title[i]; // set the value
opt.text = title[i]; // set the text
sel.appendChild(opt); // add it to the select
}
}
HTML代码
<Select onclick="setRuleName();" id="dropping" >
</Select>
应'myCars [I]'不'标题[I]' – ashley
已经尝试将其更改为myCars ash仍然不工作 – user3287181
您不应该调用'onclick'函数,或者每次单击时都会附加'option's。 – Skwal