嗯,这不是关于CSS,这是关于Javascript。 据我所知新块中的块模式显示元素,而行内模式显示元素而不开始新行:Reference。为什么复选框不以块模式显示? - Javascript
请看下面的javascript 点击主复选框后,它只显示一组复选框。如果不是,他们是隐藏的。
function prepareEventHandlers(){
//This is the main checkbox
var mainCheck=document.getElementById("mainCheck");
//This is the corresponding div
var displayResult=document.getElementById("showHide");
mainCheck.onchange=function(){
//check whether the state of the checkbox is checked or not
if(mainCheck.checked){
//if it is checked the div is displayed
displayResult.style.display="block";
}
else{
//if it is not clicked div is not displayed
displayResult.style.display="none";
}
};
//div is set to not to display in the initial page load
displayResult.style.display="none";
}
//prepareEventHandlers() will be executed once the page is loaded.
window.onload=function(){
prepareEventHandlers();
}
该代码工作正常。但我想你把重点放在这几行
if(mainCheck.checked){
displayResult.style.display="block";
}
即使显示模式是挡住了我的所有复选框出现内嵌单击主复选框时。这是为什么? 任何形式的解释将不胜感激
你不能改变某些风格的一些元素(如复选框和下拉列表)。如果你的谷歌样式的复选框,你会看到有很多js插件可以帮助实现“样式”复选框,而实际上你所做的只是样式标签 – Pete