DOM selectedIndex 实例应用

语法:selectObject.selectedIndex=number,可设置或返回下拉列表中被选选项的索引号。

实例:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
<script>
function  selectIndex(num){
 document.getElementById("mySelect").selectedIndex = num;  
}
</script>
</head>

<body>
<form>
Select your favorite fruit:
<select id="mySelect">
  <option selected="selected">Apple</option>
  <option>Orange</option>
  <option>Pineapple</option>
  <option>Banana</option>
</select>
<br /><br />
<input type="button" onclick="selectIndex(1)"
value="选择Orange"><input type="button" onclick="selectIndex(2)"
value="选择Pineapple"><input type="button" onclick="selectIndex(3)"
value="选择Banana"><input type="button" onclick="selectIndex(0)"
value="选择Apple">
</form>

</body>
</html>

 

你可能感兴趣的:(dom,selectedIndex,实例应用)