JS简单操作select和dropdownlist实例
本文实例讲述了JS简单操作select和dropdownlist的方法。分享给大家供大家参考。具体实现方法如下:
一、js选中服务器控件select与dropdownlist
1.js操作服务器控件select
<selectid="selectID"onchange="returnshowMessage()"> <optionvalue="0">==请选择==</option> <optionvalue="1">是</option> <optionvalue="2">否</option> </select>
<scripttype="text/javascript"language="javascript"> functionshowMessage(){ if(document.getElementById("selectID").options[document.getElementById("selectID").selectedIndex].value==1){ alert("你好,你选择了第1个"); document.getElementById("txtContractName").setAttribute("enable",false); } elseif(document.getElementById("selectID").options[document.getElementById("selectID").selectedIndex].value==2){ alert("你好,你选择了第2个"); } } </script>
//js操作服务器控件dropdownlist <asp:DropDownListID="ddlFolder"runat="server"SkinID="ddlSkin"AutoPostBack="false"OnSelectedIndexChanged="ddlFolder_SelectedIndexChanged"> <asp:ListItemValue="0">选项0</asp:ListItem> <asp:ListItemValue="1">选项1</asp:ListItem> </asp:DropDownList> <asp:DropDownListID="ddlFolder"runat="server"SkinID="ddlSkin"AutoPostBack="false"OnSelectedIndexChanged="ddlFolder_SelectedIndexChanged"> <asp:ListItemValue="0">选项0</asp:ListItem> <asp:ListItemValue="1">选项1</asp:ListItem> </asp:DropDownList>