0

次の例を検討してください。

<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'); を使用しています。ここで機能します。別の関数を使用する必要がありますか? マイクロソフトだけの何か?

4

1 に答える 1

-1

これは恐ろしいことですが、指定されたクラスを削除し、他のすべてを保持します。

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();
于 2013-07-22T01:19:57.133 に答える