jquery - 检查同一索引处的无线电组值
问题描述
我有两个无线电组,当我获得第一组检查值时,我无法使用以下代码在同一索引处设置另一个组:
$('input[name="service_type[]"]:checked').each(function(index) {
$("input[name=service_type1["+index+"]]").attr('checked', 'checked');
});
语法错误,无法识别的表达式:input[name=service_type1[0]]
$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.'">';
解决方案
使用 attr 定位元素应该有"
,你错过了它们。
代替
$("input[name=service_type1["+index+"]]")
做
$('input[name="service_type1[' + index + ']"]');
推荐阅读
- c# - Discord.Net 服务器请求重新连接导致音乐播放器出现问题
- python - 如何完全卸载 anaconda 和 jupyter?视窗 10
- postgresql - 如何在 Windows 中更改 postgres 的默认用户名(不将用户名 postgres 重命名为某些东西)
- python - 我无法在 osx11.1 上打开 IDLE3
- azure - Azure CDN 将图像转换为 webp
- python - 如何提取最小列表值的索引位置?
- excel - Microsoft Excel 中的字母数字验证
- haskell - Haskell - 永久暴露隐藏的包
- batch-file - 有没有办法在批处理文件中制作检查点系统?
- r - 空间数据和并行计算