我一直在尝试根据单选按钮更改CSS类,它确实有效,但它只会运行一次.例如,如果我选择白色单选按钮然后选择橡木,选择白色不会做任何事情,直到页面刷新.我肯定做错了什么,任何帮助都会受到赞赏.
$("#radio").on('change','input[type=radio]', (function() {
if($("#oakradio").is(":checked")) {
$("#over").removeAttr();
$('#over').addClass('oak');
}
else if($("#whiteradio").is(":checked")) {
$("#over").removeAttr();
$('#over').addClass('white');
}
else if($("#mocharadio").is(":checked")) {
$("#over").removeAttr();
$('#over').addClass('mocha');
}
}));Run Code Online (Sandbox Code Playgroud)
#over.mocha {
background-image: url("https://photography.bytebros.com.au/wp-content/uploads/sites/5/2017/09/pan_mocha.jpg");
background-repeat: no-repeat;
height: 515px;
width: 1190px;
margin: 0 auto 30px;
position: relative;
}
iframe {
height: 333px;
width: 1000px;
position: absolute;
top: 93px;
left: 93px;
}
#over.white {
background-image: url("https://photography.bytebros.com.au/wp-content/uploads/sites/5/2017/09/pan_white.jpg");
background-repeat: no-repeat;
height: 515px;
width: 1190px;
margin: 0 auto 30px;
position: relative;
}
#over.oak {
background-image: url("https://photography.bytebros.com.au/wp-content/uploads/sites/5/2017/09/pan_oak.jpg");
background-repeat: no-repeat;
height: 515px;
width: 1190px;
margin: …Run Code Online (Sandbox Code Playgroud)