Ahm*_*ess 3 html javascript css
我<noscript>没有启用javascript时使用标签来隐藏某些元素; 但是,它似乎没有用.
我的文件声明:
<!DOCTYPE html>
Run Code Online (Sandbox Code Playgroud)
在我的文件的末尾,我键入以下内容:
<noscript>
<style type="text/css" scoped> #status {display:none;} </style>
</noscript>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
但即使在禁用JS之后,#status div仍然存在.我在这里错过了什么吗?
Mat*_*all 11
删除标记的scoped属性style.这使得CSS严格适用于<noscript>标签.
如果存在此属性,则样式仅适用于其父元素.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style#Attributes
一个更简单的管理解决方案是默认隐藏元素并使用它:
<script>document.getElementById('status').style.display='block';</script>
Run Code Online (Sandbox Code Playgroud)
(或基于同等类别的解决方案)