2014-03-19 57 views
0

我有dropdownlist的數量,所以我想改變每個dropdownlist在窗體中的事件,當我選擇特定的dropdownlist項目,然後它將觸發特定的dropdownlist事件... 這裏是兩個示例下拉列表的jQuery與asp.net dropdownlist

<asp:DropDownList ID="ddlGender" runat="server" AutoPostBack="True"> 

 <asp:DropDownList ID="ddlMaritalStatus" runat="server" AutoPostBack="True"> 

請儘快 感謝喲幫我ü

我想這

$(document).ready(function() { 
    $('input:text').each(function() { 
     $(this).attr('disabled', true); 
    }); 
    $("select").change(function() { 
     alert(this.value); 
     if (this.value != "User Select") { 
      alert(this.value); 
      $('input:text').each(function() { 
       $(this).attr('disabled', false); 
      }); 

     } 
     if (this.value == "User Select") { 
      $('input:text').each(function() { 
       $(this).attr('disabled', true); 
      }); 
     } 
    }) 
}); 

這裏最後一個條件不能正常工作,請幫助

+0

給出@ user..your問題不是在全部清楚..解釋更多。 –

+0

你試過了什麼?什麼不起作用?這與jQuery有什麼關係? (提示:這些設置爲'AutoPostBack =「True」'這將重新加載整個頁面,呈現任何JavaScript事件處理程序模擬。) – David

回答

1

您可以指定一個公共類的所有下拉列表,並使用此類選擇器使用jQuery

更改事件綁定

HTML

<asp:DropDownList ID="ddlGender" class="ddl" runat="server" AutoPostBack="True"> 
<asp:DropDownList ID="ddlMaritalStatus" class="ddl" runat="server" AutoPostBack="True"> 

的Javascript

$('.ddl').change(function(){ 
     alert(this.id); 
}); 

如果你不想使用類選擇,你需要用id選擇綁定事件

$('#<%= ddlGender.ClientID %>, #<%= ddlMaritalStatus.ClientID %>').change(function(){ 
    alert(this.id); 
}); 
0

您可以編寫JavaScript函數,並調用它的onchange dropdownlist事件...

DropDownList ID="ddlGender" class="ddl" runat="server" AutoPostBack="True" onchange="Check()"> 
    <asp:DropDownList ID="ddlMaritalStatus" class="ddl" runat="server" AutoPostBack="True" onchange="Check()"> 

    function Check() 
    { 
     alert('Hii'); 
    } 
0

使用SelectedIndexChanged事件。

<asp:DropDownList ID="ddlGender" runat="server" AutoPostBack="True" OnSelectedIndexChanged="EventHandler1"> 
    <asp:DropDownList ID="ddlMaritalStatus" runat="server" AutoPostBack="True" OnSelectedIndexChanged="EventHandler2"> 

在代碼隱藏在下方添加功能,用於每個下拉列表

void EventHandler1(Object sender, EventArgs e) 
{ 
    // code for event handler1 
} 


void EventHandler2(Object sender, EventArgs e) 
{ 
    // code for event handler1 
} 

詳情檢查例如低於鏈路

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.selectedindexchanged(v=vs.110).aspx

+0

Thanx兄弟,但我想用jQuery或JavaScript ... Thanx:D – mmj89