![](/img/trans.png)
[英]Show and Hide div's javascript works in IE but not FF or Chrome
[英]Show hidden div, why code works in FF/Chrome but NOT in IE9?
考慮以下示例:
<html>
<head>
</head>
<body>
<style type="text/css">
.hide
{
display: none;
}
</style>
<button style="width:200;height:20;background-color:#B4CFEC;font: bold 10px Verdana" onclick="document.getElementById('CUST_CLASS').classList.remove('hide');" >CUSTOMER DIMENSION</button>
<div class="hide" id="CUST_CLASS">"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</div>
</body>
</html>
我正在使用document.getElementById('id')。classList.remove('class'); 在這里起作用。 我應該使用其他功能嗎? 只有微軟嗎?
這很可怕,但是刪除了指定的類,並保留了所有其他類:
onclick="document.getElementById('CUST_CLASS').setAttribute('class', document.getElementById('CUST_CLASS').getAttribute('class').replace('hide', ''));"
如前所述,IE9不支持classList
,因此您可以將其填充,也可以使用可處理瀏覽器兼容性的jQuery。 這是與您的代碼等效的jQuery:
$("#CUST_CLASS").removeClass("hide");
但是,如果您的hide
類僅用於切換可見性,則可以進一步簡化:
$("#CUST_CLASS").hide();
$("#CUST_CLASS").show();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.