這是一款簡單實用的網頁特效獲取select的值哦,我們利用getelementbyid獲取 select id=cc的,然後用option索引當前option的值哦
<!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=gb2312" />
<title>js獲取select下拉清單的值</title>
<script language="網頁特效">
function getvalue()
{
var t = document.getelementbyid("cc");
alert(t.options[t.selectedindex].value);
}
function addselect()
{
var selectvar = docuemnt.all('select1');< br> var options = selectvar.options;
var index = selectvar.selectedindex;
var selectvalue = options[index ];
options[i] = new option("增加了值","value");
}
</script>
</head>
<body>
<select name="select1" id="cc" onchange="getvalue();" >
<option value="111c">--投稿人--</option>
<option value="jzread.com">--管理員--</option>
</select>
<a href="#" onclick="addselect ();" >給select增加選項</a>
</body>
</html>