㈠ 用js給select插入option
1、使用innerHTML
<script>
varshosetype=document.createElement("select");//創建select標簽
shosetype.setAttribute("id","sc");//設置select的id為「sc"
document.body.appendChild(shosetype);//將select添加到body
varoption="<optionvalue="1">添加成功</option>";//新建options
shosetype.innerHTML=option;//將option添加到select
</script>
2、options.add
//根據select查找對象,
varobj=document.getElementById('mySelect');//獲取到id為'mySelect'的select元素
//添加一個選項
obj.add(newOption("文本","值"));//添加select的options這個只能在IE中有效
obj.options.add(newOption("text","value"));//添加select的options這個兼容IE與firefox
㈡ JS如何動態給select的option賦值
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
<script type="text/javascript">
function change (){
var sel = document.getElementById('sel');
sel.options[0].value = 111;
sel.options[0].text = 111;
}
</script>
</head>
<body>
<select id="sel" style="width:100px;">
<option value="1">1</option>
</select>
<a href="javascript:change();">UPDATE</a>
</body>
</html>
看看是不是你想要的效果,可以根據自己的需求修改一下。