您的位置:首页 > Web前端 > JavaScript

js如何控制select控件(下拉列表)

2008-05-09 10:31 591 查看
把下面的代码保存为html文件在浏览器打开就可以看到效果了。

<!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>Select Test</title>

</head>

<script language="javascript">

function $(o)

{

return document.getElementById(o);

}

</script>

<body>

<p>

<select name="Region" id="Region">

<option value="790">全部</option>

<option value="791">济南</option>

<option value="792">青岛</option>

</select>

</p>

<p>

<input type="button" name="Submit1" value="this.selectedIndex" onclick="alert($('Region').selectedIndex);" />

<input type="button" name="Submit2" value="this.value" onclick="alert($('Region').value);" />

<input type="button" name="Submit3" value="this.option[i].value" onclick="alert($('Region').options[$('Region').selectedIndex].value);" />

<input type="button" name="Submit4" value="this.option[i].text" onclick="alert($('Region').options[$('Region').selectedIndex].text);" />

</p>

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: