我有3個單獨的div(在aspx頁面中並使所有3個div可見=「false」)。使用javascript無法隱藏/顯示div面板
根據病情,我不得不一次顯示1個格和remaning 2層div的隱藏
我做在JavaScript爲使1個格爲style.visibility = "block";
和其他2周的div到Style.Add("display", "none");
同時運行它是拋出錯誤味精爲:
無法獲得的財產「風格」的值:未定義的對象爲空或
下面是代碼,在ASPX:
<div runat="server" id="div1" visible="false">
..
</div>
<div runat="server" id="div2" visible="false">
..
</div>
<div runat="server" id="div3" visible="false">
..
</div>
$(document).ready(function() {
var val = "xx1" (or "xx2" or"xx3")
switch (val) {
case "xx1":
document.getElementById('ctl00_ContentPlaceHolder2_div1').Style.Add("display", "none");
// document.getElementById('ctl00_ContentPlaceHolder2_div1').style.visibility = "hidden";
document.getElementById('ctl00_ContentPlaceHolder2_div2').style.visibility = "block";
//document.getElementById('ctl00_ContentPlaceHolder2_div2').style.visibility = "visible";
document.getElementById('ctl00_ContentPlaceHolder2_div3').Style.Add("display", "none");
case "xx2":
document.getElementById('ctl00_ContentPlaceHolder2_div1').Style.Add("display", "block");
document.getElementById('ctl00_ContentPlaceHolder2_div2').style.visibility = "none";
document.getElementById('ctl00_ContentPlaceHolder2_div3').Style.Add("display", "none");
case "xx3":
document.getElementById('ctl00_ContentPlaceHolder2_div1').Style.Add("display", "none");
document.getElementById('ctl00_ContentPlaceHolder2_div2').style.visibility = "none";
document.getElementById('ctl00_ContentPlaceHolder2_div3').Style.Add("display", "block");
});
看起來您使用的是JQuery,爲什麼不在JQuery中編寫其餘的內容? – VIDesignz
如果我在加載頁面的時候使可見=「true」(在製作所有3個div的aspx頁面中),它顯示所有3個div,然後2個div隱藏起來,即使它們被隱藏,它們也佔用每個空間。 – user2522503
爲什麼要添加樣式?你可以使用'.style.display ='none';'或'.style.display ='block';' – VIDesignz