0

我有一个带有下拉列表(值为 1, 2, 3 )和一个文本框的 ASP.NET 中继器控件。因此,在每个带有下拉列表和文本框的 ItemTemplate 中生成/创建了多个代码实例。

我正在尝试在 jQuery/javascript 中创建一个函数,每当下拉列表中的值被选择为 1 时,文本框都应该被禁用。现在这个下拉列表可以是任何人说的第一、第三或第五......并且相应的文本框应该被禁用。

任何人都可以指导我能够为中继器中的每一行进行这项工作吗?

谢谢!

4

2 回答 2

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);
    }
});
于 2012-09-05T07:50:24.063 回答
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
});
于 2012-09-05T07:45:24.053 回答