我正在修改一个旧的网站,并且专注于让Javascript/jQuery尽可能的不引人注目。我正在寻找一些关于项目的一部分的建议: UJ要求,如果Javascript在浏览器中被关闭,所有网站内容仍然对用户可用。我网站的一部分有一个很大的项目列表。列表中的每个项目都有自己的描述,默认情况下使用CSS display:none来隐藏它。单击该项目将使用jQuery .toggle():切换描述的可见性,因此无法使用Javascript (无论出于何种原因)的人将永远看不到它。如果我使用Javascript/jQuery而不是CSS来隐藏描述,当页面加载时,它们都是瞬间可见的,这是我想要避免的。那么最好的解决方案是什么呢?
发布于 2012-01-30 19:13:49
你有没有想过使用一种类似于用现代实现的方法?
CSS类是由一个脚本添加到HTML标签中的,该脚本会使不同的CSS选择器匹配。
<html>
<head>
<!--
Putting this script in the head adds the "js"
class to the html element before the page loads.
-->
<script type="text/javascript" language="javascript">
document.documentElement.className = "js";
</script>
<style type="text/css">
/*
Only apply the hidden style to elements within the HTML element
that has the js class
*/
.js .description {display:none;}
</style>
</head>
<body>
<span class="description">Example</span>
</body>
</html>https://stackoverflow.com/questions/9062811
复制相似问题