当CSS标签输入无线电时混淆
我正在编写代码以更改标签样式时,当它检查其收音机时。这是我的代码:
<body>
<div class="input-area input-area-sp">
<label id="daily" class="container-radio checked">
<input type="radio" checked="checked" name="radio" class="radio">
<span class="checkmark"></span>
<em>Daily</em>
</label><br/>
<label id="weekly" class="container-radio">
<input type="radio" name="radio" class="radio">
<span class="checkmark"></span>
<em>Weekly</em>
</label>
</div>
<script>
$(document).on("click", 'input.radio', function () {
if ($(this).is(":checked")) {
$('label.checked').removeClass('checked');
$(this).parent().addClass("checked");
}
});
</script>
</body>
上课。
<style>
.checked {
color:green;
}
</style>
在这里一切正常。
但是,当我将类名称从“检查”更改为诸如“ Active”(在CSS和jQuery中)之类的其他内容时,在未选择的情况下,标签无法删除类(所有标签仍然是绿色的)。
任何人都可以为我解释一下。 非常感谢。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可以更改班级名称,您可能需要参考我的代码
I can change the class name, you might want to refer to my code
https://jsfiddle.net/15frkLpe/
你可以尝试这样的东西,
上面的代码将从“ .input-raea”中的所有元素中删除并删除“ Active”类,并在父元素中添加“ Active”类。
You could try something like this,
Above code will take and remove '.active' class from all elements inside the '.input-area' and add '.active' class to the parent element.