我有一个ASP。NET Repeater控件,带有下拉列表(值为1、2、3)和文本框。因此,在每个ItemTemplate中都会生成/创建多个代码实例,其中包含一个下拉列表和一个文本框。
我试图在jQuery/javascript中创建一个函数,每当下拉列表中的值被选择为1时,文本框都应该被禁用。现在这个下拉列表可以是任何人,比如第一、第三或第五。。并且重复文本框应该被禁用。
有人能指导我在中继器的每一行都能做到这一点吗?
谢谢!
如果中继器渲染为表。那么你可以试试。
$("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);
}
});
试试这个
$('.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
});