Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.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 我想使用for循环来获取jquery中复选框和文本框的id_Javascript_Jquery_Html_For Loop - Fatal编程技术网

Javascript 我想使用for循环来获取jquery中复选框和文本框的id

Javascript 我想使用for循环来获取jquery中复选框和文本框的id,javascript,jquery,html,for-loop,Javascript,Jquery,Html,For Loop,我的第一个复选框是完美的。但我想为14个复选框和文本框使用for循环。我的脚本用于当我单击复选框时,只有文本框是启用的。 我想使用for循环来获取jquery中复选框和文本框的id <script> $(document).ready(function() { $("#check_0").click(function () { if ($(this).is(":checked")) { $("#textbo

我的第一个复选框是完美的。但我想为14个复选框和文本框使用for循环。我的脚本用于当我单击复选框时,只有文本框是启用的。 我想使用for循环来获取jquery中复选框和文本框的id

<script>
    $(document).ready(function() { 
       $("#check_0").click(function () { 
           if ($(this).is(":checked")) {
               $("#textbox_0").removeAttr("disabled");
               $("#textbox_0").focus();
           }
           else
           {
              $("#textbox_0").attr("disabled", "disabled");
           }
         });
       });


</script>

您可以使用名称选择器选择所有复选框,因为所有复选框都具有相同的名称,然后您可以在与复选框相同的范围内找到tech input元素

$document.readyfunction{ $'input[name=technology]'。单击函数{ var$input=$this.closest'span'。查找'input[name=tech]; $input.prop'disabled',!this.checked; 如果这个被选中了{ $input.focus; } }; };
不需要for循环,您可以使用选择器。然后获取号码并在您可以使用回调函数更新后查找文本框

$'[id^=检查]'。单击函数{ //选择id名称为的所有元素以“检查”开头_ //然后绑定单击事件 $textbox\+this.id.split'\[1].propdisabled,functioni,v{ //从id获取号码并获取文本框 返回!v; //基于以前的值更新选中的特性值 }.重点; //聚焦文本字段 }; 我想去平野 网间网操作系统 安卓 PHP .NETMVC JAVA 数据库管理员 搜索引擎优化 我想去平野 用户界面设计器 质量保证 项目经理 业务分析师 技术分析员 奥多 冷聚变
正如我看到的html结构一样,您可以简单地更改对应文本框的disable属性,如下所示

$(document).on('click','input[id^="check_"]',function(){
    if($(this).prop('checked'))
    {
        $(this).parents('span').find(':text').removeAttr('disabled');
        $(this).parents('span').find(':text').focus();
        return;
    }
    $(this).parents('span').find(':text').attr('disabled','disabled');
});

这个脚本是为我想雇用Field而写的为什么不使用类?我不想为单个复选框编写脚本,所以我想为所有复选框使用循环。是的,这就是为什么需要类。。。否则,您将使用dom。@Priya:很高兴为您提供帮助: