我有三个 div 当我想使用复选框时我应该有新的 div 如果我检查 car1 而未选中 car2 我应该有红色汽车但如果检查 car1 而检查 car2 我应该有黑色汽车
<div id="carblack">
car black
</div>
<div id="carred" style="display:none">
car red
</div>
<div id="carblue" style="display:none">
car blue
</div>
<input type="checkbox" id="car1" name="vehicle" value="red" checked/>
<input type="checkbox" id="car2" name="vehicle1" value="blue" checked/>
$('#car1').change(function () {
if($(this).attr("checked")){
document.getElementById("carred").style.display = "block";
document.getElementById("carblack").style.display = "none";
} else{
document.getElementById("carblack").style.display = "block";
document.getElementById("carred").style.display = "none";
}
});
$('#car2').change(function () {
if($(this).attr("checked")){
document.getElementById("carblue").style.display = "block";
document.getElementById("carblack").style.display = "none";
} else{
document.getElementById("carblack").style.display = "block";
document.getElementById("carblue").style.display = "none";
}
});