如何通过jQuery / javascript选择ASP.NET转发器中的下拉控件?

时间:2012-09-05 07:32:21

标签: jquery asp.net

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

我正在尝试在jQuery / javascript中创建一个函数,只要下拉列表中的值被选为1,就应该禁用文本框。现在这个下拉列表可以是第一个,第三个或第五个......并且相应的文本框应该被禁用。

有人可以指导我能够为Repeater中的每一行做这项工作吗?

谢谢!

2 个答案:

答案 0 :(得分: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
});

答案 1 :(得分: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);
    }
});