如果是PHP的话,读取数据库的时候把读取到的部分存在$a
<option value="<?php echo $a?>">选项名称</option>这样就可以了。
<select name="sel1"></select><script>
var sel=document.getElementsByName("sel1")
var option=["option1","option2","option3","......"]
for(var i=0i<option.lengthi++){
var opt=document.createElement("option")
opt.innerHTML=option[i]
sel[0].appendChild(opt)
//getElementsByName返回的是数组。所以为sel[0]。建议设置select的id,然后用getElementById获得select对象。
}
</script>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)