Javascript 如何循环遍历每个文本框,并在所有其他文本框(如果输入了文本框)中将文本框值设置为禁用
我有一个表。在表中我有一些文本框。我想禁用所有文本框 输入一个后使用相同的名称。 如何使用jquery实现这一点? 我对下面的选择框使用了相同的东西Javascript 如何循环遍历每个文本框,并在所有其他文本框(如果输入了文本框)中将文本框值设置为禁用,javascript,jquery,Javascript,Jquery,我有一个表。在表中我有一些文本框。我想禁用所有文本框 输入一个后使用相同的名称。 如何使用jquery实现这一点? 我对下面的选择框使用了相同的东西 <script> $(document).ready(function(){ $('select[name*="course"]').live('change', function() { $('select[name*="course"] option').attr('disabled
<script>
$(document).ready(function(){
$('select[name*="course"]').live('change', function() {
$('select[name*="course"] option').attr('disabled',false);
// loop each select and set the selected value to disabled in all other selects
$('select[name*="course"]').each(function(){
var $this = $(this);
$('select[name*="course"]').not($this).find('option').each(function(){
if($(this).attr('value') == $this.val())
$(this).attr('disabled',true);
});
});
});
});
</script>
But i want to do it for textboxes.How to do?
$(文档).ready(函数(){
$('select[name*=“course”]”)。live('change',function(){
$('select[name*=“course”]option').attr('disabled',false);
//循环每个选择,并在所有其他选择中将所选值设置为禁用
$('select[name*=“course”]”)。每个(函数(){
var$this=$(this);
$('select[name*=“course”]”)。不是($this)。查找('option')。每个(函数(){
if($(this.attr('value')==$this.val())
$(this.attr('disabled',true);
});
});
});
});
但是我想为文本框做这个。怎么做?
设置更改
事件,检查长度。如果存在长度,请禁用具有相同名称的所有其他名称:
$("table input:text").change(function() {
if (this.value.length > 5) {
$("table").find("input:text[name=" + this.name + "]").not(this).prop("disabled", true);
}
});
编辑:接受@adeneo的建议 设置
更改事件,检查长度。如果存在长度,请禁用具有相同名称的所有其他名称:
$("table input:text").change(function() {
if (this.value.length > 5) {
$("table").find("input:text[name=" + this.name + "]").not(this).prop("disabled", true);
}
});
编辑:接受@adeneo的建议 想法:
在文本字段更改中:
检查是否输入了触发禁用的值
获取更改文本字段的名称
搜索所有其他文本字段并将其设置为禁用(或在第一步中检测到的启用)
代码:
想法:
在文本字段更改中:
检查是否输入了触发禁用的值
获取更改文本字段的名称
搜索所有其他文本字段并将其设置为禁用(或在第一步中检测到的启用)
代码:
你的代码到目前为止?HTML?到目前为止你的代码是什么?HTML?JS?你的意思可能是find()
,而不是filter()
,并且可能添加一个而不是(这个)
@adeneo--ah yes-a和yes。编辑!您的意思可能是find()
,而不是filter()
,并且可能添加一个而不是(这个)
@adeneo--ah yes-a和yes。编辑!