Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.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 - Fatal编程技术网

Javascript 如何循环遍历每个文本框,并在所有其他文本框(如果输入了文本框)中将文本框值设置为禁用

Javascript 如何循环遍历每个文本框,并在所有其他文本框(如果输入了文本框)中将文本框值设置为禁用,javascript,jquery,Javascript,Jquery,我有一个表。在表中我有一些文本框。我想禁用所有文本框 输入一个后使用相同的名称。 如何使用jquery实现这一点? 我对下面的选择框使用了相同的东西 <script> $(document).ready(function(){ $('select[name*="course"]').live('change', function() { $('select[name*="course"] option').attr('disabled

我有一个表。在表中我有一些文本框。我想禁用所有文本框 输入一个后使用相同的名称。 如何使用jquery实现这一点? 我对下面的选择框使用了相同的东西

      <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。编辑!