Javascript 我怎样才能加上?’;残疾人士;基于表中下拉选择的文本字段属性?
我试图在每一行中都有一个字段,只有在选中该行中的特定下拉列表时才需要。因此,如果选择值1,则它将被禁用 以下是我所拥有的: Jquery: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
<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);
}
});