我需要一些关于 javascript 的帮助。
这是 JSFIDDLE 中代码的链接:http://jsfiddle.net/Gopher69/B98kZ/4/
我的 JS 是:
$(document).ready(function() {
//add the Selected class to the checked radio button
$('[type=radio]').parent().addClass("selected");
//If another radio button is clicked, add the select class, and remove it from the previously selected radio
$('input').click(function() {
$('input:not(:checked)').parent().removeClass("radio validate-one-required-by-name product-custom-option").find("class").html("radio validate-one-required-by-name product-custom-option");
$('input:checked').parent().addClass("radio validate-one-required-by-name product-custom-option").find("class").html("radio validate-one-required-by-name product-custom-option active");
});});
我想调整单选按钮的背景颜色,就像我用 css 调整悬停效果一样。因此,当单选按钮处于事件状态时,我需要向类中添加类似“选中”的内容。
我找到了这篇文章,但我没有看到前言:jQuery Checkbox selection and change class
如果有人能帮助我,我将不胜感激。
最佳答案
你可以使用纯 css 来做到这一点:
input[type="radio"]:checked {
/* put some style here */
}
关于javascript - JQuery:单击单选按钮时更改类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14040353/