2012-11-20 24 views
0

我試圖根據Windows 8應用程序中的用戶設置顯示或隱藏div。我有2周的div在我的html文件:Windows 8應用程序開發JavaScript - 在JavaScript代碼中顯示/隱藏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中執行此

回答

1

的一種方法是使用樣式屬性:

var fillBlank = document.getElementById("fillBlank");  
fillBlank.style.display = "none"; 

設置的style.display爲「」將使其可見用什麼都顯示時間的元素目前已成立。

0

你非常接近!

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'; 
    } 
}