js移除input单选框(radio)选中效果

上午做类似于这样一个单选框效果,需要把弹窗内单选框后的文本赋值到弹窗父页面。

可是在js中移除最开始是这么做的。

$('.chose-box-li').children('input').attr('checked', 'true')
$(this).children('input').attr('checked', 'true');
看上去好像没什么问题,可是在开发者模式中查看:
同名input[type="radio"]选中其他时候,上一个选中的input依然是checked="checked"状态,选中状态没有移除。
直接结果就是我们获得赋值文本文本错误,后修改为下代码,则修正错误
$('.chose-box-li').children('input').removeAttr('checked')
$(this).children('input').attr('checked', 'true');

猜你喜欢

转载自blog.csdn.net/jpjp2020/article/details/81260450