2012-09-05 35 views
0

我有一個下拉列表(具有值1,2,3)和一個文本框的ASP.NET Repeater控件。因此,在每個ItemTemplate中使用下拉和文本框生成/創建多個代碼實例。如何通過jQuery/javascript在ASP.NET中繼器中選擇下拉控件?

我想在jQuery/javascript中創建一個函數,只要下拉列表中的值選擇爲1,就應該禁用文本框。現在,這個下拉菜單可以是任何人說的第一,第三或第五......並且相應的文本框應該被禁用。

任何人都可以親切地指導我能夠在Repeater中的每一行進行這項工作嗎?

謝謝!

+1

發佈您的中繼器標記。 –

回答

0

試試這個

$('.dropdown').change(function() 
{ 
    //include condition to determine "if dropdown is selected to be 1" 

    var $row = $(this).parents('tr:first'); //find the row in which this dropdown is 
    if($(this).val() == 1) 
    { 

    $row.find('.textbox:first').attr('disabled','disabled');​​​​​​ //assuming you put a class on your textbox 
    //$row.find('.textbox:first').attr('disabled','true');​​​​​​ 
    //$row.find('.textbox:first').prop('disabled','true');​​​​​​ 
    } 
    else 
     $row.find('.textbox:first').attr('enabled','true'); //assuming you put a class on your textbox 
}); 
+0

我試過這段代碼,但是它只在我只有一箇中繼器項目的時候有效,在我添加第二個時候,它停止工作。另外,我的文本框中沒有課程,我們沒有其他方法可以訪問它嗎? – user1645732

+0

'input [type = text]'like @Yograj posted in his answer。將一個類添加到文本框需要什麼?我這樣做,以保持我的jQuery簡單 – codingbiz

+0

非常感謝,我不想做輸入[類型=文本],因爲將來可能會添加另一個文本框中繼器項目,然後這兩個將獲得禁用。另外正如我所提到的,我試過這段代碼,但它只在我們只有單箇中繼器項目時有效,此時我添加了第二個,它停止工作。 – user1645732

0

如果您的中繼器呈現爲表。那麼你可以試試。

$("select").change(function(){ 
    var _this = $(this); 
    var parentRow = _this.closest('tr'); 
    if(_this.val() == "1"){ 
     parentRow.find("input[type=text]").prop("disabled", true); 
    }else { 
     parentRow.find("input[type=text]").prop("disabled", false); 
    } 
}); 
相關問題