JRO*_*ROB 5 html javascript css
我只是在关闭Javascript时尝试定义特定的CSS样式.我在用:
<noscript>
<style type="text/css">
.needjs {display:none !important;}
.mwnojs { margin-top: 40px !important; }
</style>
</noscript>
Run Code Online (Sandbox Code Playgroud)
在尝试验证页面源时,我收到错误"元素样式不允许作为此上下文中元素noscript的子元素".
那么,在保持标记有效的同时,我该如何做呢?
尝试这样的事情:
<html class="nojs">
<head>
<script type="text/javascript">
document.getElementByTagName("html")[0].className="";
</script>
<style>
html#nojs {
/* do something */
}
</style>
Run Code Online (Sandbox Code Playgroud)
这会在加载页面时删除一个类。如果未激活 javascript,则不会删除该类。