DropDownList添加客户端下拉事件操作
如果要想给DropDownList服务器控件添加客户端下拉事件,我们可以强制给它添加onchange事件,尽管在控件中没有这个方法的提示。添加完这个事件还不能达到目的,还要设置AutoPostBack属性为false,不让它回发后台事件。
以下就是为大家分享的代码:
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>DropDownList添加客户端下拉事件</title>
<scripttype="text/javascript">
functiongetDropDownList(){
varddl1=document.getElementById("<%=ddl1.ClientID%>");
vartext=ddl1.options[ddl1.options.selectedIndex].text;//获取text值
varvalue=ddl1.value;//获取value值
alert("Text:"+ddl1.options[ddl1.options.selectedIndex].text+",Value:"+ddl1.value);
}
</script>
</head>
<body>
<formid="form1"runat="server">
<asp:DropDownListID="ddl1"runat="server"AutoPostBack="false"onchange="getDropDownList();">
<asp:ListItemText="T1"Value="V1"Selected="True"></asp:ListItem>
<asp:ListItemText="T2"Value="V2"></asp:ListItem>
<asp:ListItemText="T3"Value="V3"></asp:ListItem>
</asp:DropDownList>
</form>
</body>
</html>
总结一下,也就是说,要想给DropDownList下拉框添加客户端下拉事件,必须做两步工作,一是添加强制onchange事件,二是把AutoPostBack属性设为false,就是这么简单!
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下