欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

DropDownList添加客戶端下拉事件操作

 更新時間:2015年09月29日 09:05:34   投稿:lijiao  
我們知道,DropDownList下拉框是一個服務(wù)器控件,有時候,有些朋友為了方便綁定DropDownList下拉框的選項,但又想在DropDownList實現(xiàn)客戶端的下拉事件,那該怎么實現(xiàn)呢?

如果要想給 DropDownList 服務(wù)器控件添加客戶端下拉事件,我們可以強(qiáng)制給它添加 onchange 事件,盡管在控件中沒有這個方法的提示。添加完這個事件還不能達(dá)到目的,還要設(shè)置 AutoPostBack 屬性為 false,不讓它回發(fā)后臺事件。
以下就是為大家分享的代碼:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>DropDownList添加客戶端下拉事件</title>
  <script type="text/javascript">
    function getDropDownList() {
      var ddl1 = document.getElementById("<%=ddl1.ClientID%>");
      var text = ddl1.options[ddl1.options.selectedIndex].text; //獲取text值
      var value = ddl1.value;                  //獲取value值
      alert("Text:" + ddl1.options[ddl1.options.selectedIndex].text + ", Value:" + ddl1.value); 
    }
  </script>
</head>
<body>
<form id="form1" runat="server">
  <asp:DropDownList ID="ddl1" runat="server" AutoPostBack="false" onchange="getDropDownList();">
    <asp:ListItem Text="T1" Value="V1" Selected="True"></asp:ListItem>
    <asp:ListItem Text="T2" Value="V2"></asp:ListItem>
    <asp:ListItem Text="T3" Value="V3"></asp:ListItem>
  </asp:DropDownList>
</form>
</body>
</html>

總結(jié)一下,也就是說,要想給DropDownList下拉框添加客戶端下拉事件,必須做兩步工作,一是添加強(qiáng)制onchange事件,二是把 AutoPostBack屬性設(shè)為false,就是這么簡單!

相關(guān)文章

最新評論