繁体   English   中英

使用eq的jQuery单选按钮设置失败

[英]jQuery setting of radio button using eq fails

在下面的代码中, plane.posFile是一个长度为3的字符串数组,用于标识3个单选按钮,并且这些按钮可以正确显示。

如果oSource.posfile是空字符串,则正确检查第0个按钮。

如果oSource.posfile不为空,则它是plane.posFile中的三个文件之一,只是为了进行比较必须删除文件扩展名。

发生的事情是,正确的代码(使用Firebug逐步执行)选择了要使用的索引。

它进入break语句,然后以i=1

但是,尝试设置eq(i) attr('checked',true)文件的时间。 我不明白为什么。 与使用eq(0)时的语句相同。 我一直盯着它看了几个小时,没有运气。

任何想法都将受到赞赏,包括对该方法的评论。

$wb.pcPosCfg.empty();
for (i=0; i<plane.posFile.length; i++)
     $wb.pcPosCfg.append("<input type='radio' style='width:11px' name='rbnLoadCfg' value=" + i + ">" + plane.posFile[i] + "<br>");
    if (oSource.posfile=='') {
        $('input[name="rbnLoadCfg"]:eq(0)').attr('checked',true);
    }
    else {
        for (i=0; i<plane.posFile.length; i++) {
            if (oSource.posfile==plane.posFile[i].substring(0,plane.posFile[i].length-5))
                break;
            }
        $('input[name="rbnLoadCfg"]:eq(i)').attr('checked',true);
    }
}
$('input[name="rbnLoadCfg"]:eq('+i+')').attr('checked',true);

您需要连接字符串以正确包含变量。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM