當我單擊Close this message
時,我試圖隱藏cookies-banner-bloc
div。我哪裏錯了?單擊超鏈接將div設置爲不透明度0
HTML:
<div class="cookies-banner-bloc">
<div class="cookies-banner-container">
<p>We use cookies on this website.</p>
<a class="cookies-close-button no-border">Close this Message</a>
</div>
</div>
CSS:
.hide {
opacity:0;
}
JS:
$(document).ready(function() {
if(getCookie("userclosedalert")=="true"){
$(".cookies-banner-bloc").addClass('hide');
removeClass = false;
}
$(".cookies-close-button").click(function() {
document.cookie = "userclosedalert=true";
});
});
演示: https://jsfiddle.net/28860gqj/
您可以使用顯示器無屬性來隱藏使用CSS一個div。 – Super