我正在尝试制作复选框来隐藏/显示段落,但由于某种原因,当我单击复选框时,段落不会出现,这是 JavaScript 代码:
function showPara()
{
document.getElementById("first").style.visibility=(document.formex.firstpara.checked) ? "block" : "hidden";
document.getElementById("second").style.visibility=(document.formex.secondpara.checked) ? "block" : "hidden";
document.getElementById("third").style.visibility=(document.formex.thirdpara.checked) ? "block" : "hidden";
return true:
}
这是HTML代码:
<p id="first">This is a paragraph</p>
<p id="second">This is a paragraph</p>
<p id="third">This is a paragraph</p>
<form name="formex">
<input type="checkbox" name="firstpara" onClick="showPara();"/>First Paragraph<br />
<input type="checkbox" name="secondpara" onClick="showPara();"/>Second Paragraph<br />
<input type="checkbox" name="thirdpara" onClick="showPara();"/>Third Paragrpah<br />
</form>