我正在尝试根据Windows 8应用程序中的用户设置显示或隐藏div。我的 html 文件中有 2 个div:
<div id="fillBlank"><p>Fill in the Blank area</p></div>
<div id="multipleChoice"><p>Multiple choice area</p></div>
在 JavaScript 文件中,我有:
var answerStyle = "mc";
function showArea() {
if (answerStyle == "mc") {
// Multiple choice
multipleChoice.visible = true;
fillBlank.visible = false;
} else if (answerStyle == "fb") {
// Fill in the blank
multipleChoice.visible = false;
fillBlank.visible = true;
}
}
这行不通。有什么建议吗?提前谢谢。
在 JavaScript 中执行此操作的一种方法是使用 style 属性:
var fillBlank = document.getElementById("fillBlank");
fillBlank.style.display = "none";
将 style.display 设置为 " 将使其使用元素当前设置的显示时间可见。
你很接近!
var answerStyle = "mc";
function showArea() {
if (answerStyle == "mc") {
// Multiple choice
multipleChoice.style.visibility ='visible';
fillBlank.style.visibility = 'hidden';
} else if (answerStyle == "fb") {
// Fill in the blank
multipleChoice.style.visibility = 'hidden';
fillBlank.style.visibility = 'visible';
}
}