<script type="text/javascript" language="javascript">
2 function CheckDropDownList() {
3 var dropDownList = document.getElementByIdx_x_x("<%=DropDownListID.ClientID %>");
//获取DropDownList控件
4 var dropDownListValue = dropDownList.options[dropDownList.selectedIndex].value;
//获取选择项的值
5 //注:DropDownListID是DropDownList控件的ID。
6
7 //JS验证是否有非0值:
8 if (dropDownListValue == 0) {
9 alert("请选择…….");
10 dropDownList.focus();
11 return false;
12 }
13 else {
14 return true;
15 }
16 }
17 </script>JS获取DropDownList选择项的值
最新推荐文章于 2014-09-10 15:45:45 发布
本文介绍了一个简单的 JavaScript 脚本示例,用于验证网页表单中的 DropDownList 控件是否选择了非默认值。通过获取 DropDownList 的选定值并检查其是否为初始状态(通常为0),可以有效提醒用户进行必要的选项选择。

192

被折叠的 条评论
为什么被折叠?



