获取select选中的option值,修改选中的选项,添加选项option。
<body>
<div id="div">
<form action="reg.do">
<select name="habbit" id="h">
<option value="篮球">篮球</option>
<option value="皮球">皮球</option>
<option value="羽毛球">羽毛球</option>
</select>
<input type="button" οnclick="show()" value="显示爱好">
<input type="button" οnclick="change()" value="改变爱好">
<input type="button" οnclick="addOption()" value="添加选项">
</form>
</div>
<script type="text/javascript">
function show() {
var select = document.getElementById("h");
alert(select.value);
}
function change() {
var select = document.getElementById("h");
select.options[0].selected = true;
}
function addOption() {
var select = document.getElementById("h");
var option = new Option("乒乓球","乒乓球");Option(text,value);
select.add(option);
}
</script>
</body>