首页 > 解决方案 > 检查同一索引处的无线电组值

问题描述

我有两个无线电组,当我获得第一组检查值时,我无法使用以下代码在同一索引处设置另一个组:

$('input[name="service_type[]"]:checked').each(function(index) {        
        $("input[name=service_type1["+index+"]]").attr('checked', 'checked');
        });

语法错误,无法识别的表达式:input[name=service_type1[0]]

两个名为 Single 和 Return 的输入单选按钮组

     $service.='<input type="radio" id="str"'.$i++.'"
        name="service_type1[]"
        class="radio-input return" 
        value="'.$request->service_type.'">';


$service.='<input type="radio" id="st"'.$i.'"
        name="service_type[]"
        class="radio-input single" 
        value="'.$request->service_type.'">';

标签: jquery

解决方案


使用 attr 定位元素应该有",你错过了它们。

代替

$("input[name=service_type1["+index+"]]")

$('input[name="service_type1[' + index + ']"]');

推荐阅读