Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我怎样才能加上?’;残疾人士;基于表中下拉选择的文本字段属性?_Javascript_Jquery_Html - Fatal编程技术网

Javascript 我怎样才能加上?’;残疾人士;基于表中下拉选择的文本字段属性?

Javascript 我怎样才能加上?’;残疾人士;基于表中下拉选择的文本字段属性?,javascript,jquery,html,Javascript,Jquery,Html,我试图在每一行中都有一个字段,只有在选中该行中的特定下拉列表时才需要。因此,如果选择值1,则它将被禁用 以下是我所拥有的: Jquery: <script> $(document).ready(function () { $('.Selecter').change(function () { var $this = $(this); var $row = $this.closest("tr").find('.a

我试图在每一行中都有一个字段,只有在选中该行中的特定下拉列表时才需要。因此,如果选择值1,则它将被禁用

以下是我所拥有的:

Jquery:

<script>
    $(document).ready(function () {
        $('.Selecter').change(function () {
            var $this = $(this); 
            var $row = $this.closest("tr").find('.accountNumber');
            if (this.value == "1") {
                $('#row').attr("disabled", "disabled");
            } else {
                return false;
            }
        });
    });

</script>

$(文档).ready(函数(){
$('.selector').change(函数(){
var$this=$(this);
var$row=$this.closest(“tr”).find('.accountNumber');
如果(this.value==“1”){
$(“#行”).attr(“禁用”、“禁用”);
}否则{
返回false;
}
});
});
HTML:


0
1.
2.
3.
4.
5.
6.
1.
2.
3.
4.
5.
6.
小提琴:试试这个:

Jsfiddle:

试试这个:

Jsfiddle:

  • 应用
    .attr
    方法时使用
    $row
    ,因为
    DOM
  • 使用
    .prop
    而不是
    .attr
  • 如果条件可以通过
    $row.prop(“禁用”,this.value==“1”)消除
  • 使用
    .change()
    最初调用处理程序

$('.selector').change(函数(){
$(this.closest(“tr”).find(“.accountNumber”).prop(“disabled”,this.value==“1”);
}).change()

0
1.
2.
3.
4.
5.
6.
1.
2.
3.
4.
5.
6.
  • 应用
    .attr
    方法时使用
    $row
    ,因为
    DOM
  • 使用
    .prop
    而不是
    .attr
  • 如果条件可以通过
    $row.prop(“禁用”,this.value==“1”)消除
  • 使用
    .change()
    最初调用处理程序

$('.selector').change(函数(){
$(this.closest(“tr”).find(“.accountNumber”).prop(“disabled”,this.value==“1”);
}).change()

0
1.
2.
3.
4.
5.
6.
1.
2.
3.
4.
5.
6.
您可以

$('.Selecter').change(function() {
  var val = $(this).val();
  if (val == 1) {
    $(this).closest("tr").find(".accountNumber").prop("disabled", true);

  } else {
    $(this).closest("tr").find("accountNumber").prop("disabled", false);
  }
});

代码的问题是,您将当前行的账号添加到名为
$row
的变量中,但在下一行中,您只需使用选择器“#row”,它与前一行没有任何关系。

您可以这样做

$('.Selecter').change(function() {
  var val = $(this).val();
  if (val == 1) {
    $(this).closest("tr").find(".accountNumber").prop("disabled", true);

  } else {
    $(this).closest("tr").find("accountNumber").prop("disabled", false);
  }
});

代码的问题是,您将当前行的帐号添加到一个名为
$row
的变量中,但在下一行中,您只使用选择器“#row”,它与上一行没有任何关系

$('.Selecter').change(function() {
  $(this).closest("tr").find('.accountNumber').prop("disabled", this.value == "1");
}).change();
$('.Selecter').change(function() {
  var val = $(this).val();
  if (val == 1) {
    $(this).closest("tr").find(".accountNumber").prop("disabled", true);

  } else {
    $(this).closest("tr").find("accountNumber").prop("disabled", false);
  }
});