我有以下 css 使用 after pesudo 元素创建一些自定义单选按钮:
.estimate-forms .special-smallradio:checked + label:after{content: '';width: 12px;height: 12px;border-radius: 50px;position: absolute;top: 3px;background: #99a1a7; left:3px; box-shadow: inset 0px 0px 10px rgba(0,0,0,0.3);}
当用户手动点击单选按钮时它工作正常。但是有一个实例,我需要通过使用 Jquery 更改其属性来将单选按钮标记为已选中。
$(".special-smallradio").attr("checked",true);
我的所有检测单选按钮被选中的 CSS 都不起作用。如果我尝试做的事情可行,有什么想法吗?
编辑:
这是我的单选按钮 html。正如我所提到的,它们是自定义单选按钮,可能会导致问题。
<input type="radio" name="dates[0]['response']" value="0" class="special-smallradio" id="date_0_0"/> <label for="date_0_0"></label>
<input type="radio" name="dates[0]['response']" value="1" class="special-smallradio" id="date_0_1"/> <label for="date_0_1"></label>
最佳答案
不要设置 attr('checked', true)
,而是尝试将其设置为 'checked'
我之前遇到过同样的问题,发现这个可以工作:
$(this).parent().find('a.active input:radio').attr('checked','checked');
关于jquery - 当 jquery 设置选中属性时,检测选中单选按钮的 CSS 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22161692/