下拉列表選中的文字和值的處理實例


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文檔</title>
<script language="javascript">
function outText(){
var selectId = document.getElementById("selectId");
var text =selectId.options[selectId.selectedIndex].text;
var val = selectId.options[selectId.selectedIndex].value;
alert("你選中的是值爲: "+val+" 文字爲: "+text+" 的選項");
}
</script>
</head>

<body>
<select name="select" id="selectId" οnchange="outText();">
<option value="1">AAAA</option>
<option value="2">BBBB</option>
<option value="3">CCCC</option>
</select>
</body>
</html>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章