目前,我的代码可以用在单个 radio group. 如果是多个就出现问题。 点击第二排Zzz的时候,就连上面那排的红色边框也不见了。。。

大神们!请问哪里出错了?
html
css
.discount{
border: 2px solid #cccccc;
padding:2px;
padding:10px;
width:100%;
text-align:center;
border-radius: 5px;
}
.discount.checked {
border-color: red;
}
.discount2{
border: 2px solid #cccccc;
padding:2px;
padding:10px;
width:100%;
text-align:center;
border-radius: 5px;
}
.discount2.checked {
border-color: red;
}
jquery
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
示例在这里,综合之前的回答
https://jsfiddle.net/7y2hw7L8/
代码有些改动,照例是用的 es6 的语法
因为你把 onchange 事件绑定在所有的 input:radio 元素里。所以无论你点击上面一组 radio 元素还是下面一组,你都会触发这两个 onchange 事件对应的回调。所以应该改成类似下面
或者
类名都叫 .discount 没有问题。你的 radio 应该用 name 来区分,如果想找指定name 的 radio,可以用
或者