目的:一个下拉控件,选中内容后提交到另外一个下拉控件。我想要实现,内容选择到另外一边后,是选中状态的效果。
操作:第二下拉控件是new option出来的。
我通过setAttribute添加了selected属性。document.form1.select1.options.setAttribute("selected","selected");
alert出来发现,selected属性添加在了<select>标签里,而不是<option>里。
问题:求教下哪里出问题了。或者selected属性应该怎么添加到new 出来的option中。
操作:第二下拉控件是new option出来的。
我通过setAttribute添加了selected属性。document.form1.select1.options.setAttribute("selected","selected");
alert出来发现,selected属性添加在了<select>标签里,而不是<option>里。
问题:求教下哪里出问题了。或者selected属性应该怎么添加到new 出来的option中。
应该是是通过
document.form1.select1.selectedIndex来设置默认选项
<!--
function jj () {
var opt = new Option("3","3");
opt.selected = true;
var s = document.getElementById("kk").options;
s[s.length] = opt;
}
//-->
</script>
<body>
<select id="kk">
<option value="1" selected>1</option>
<option value="2">2</option>
</select>
<input type="button" value="Click" onclick="jj()"/>
</body>