HTML“no-js”的目的是什么?类? [英] What is the purpose of the HTML "no-js" class?

查看:123
本文介绍了HTML“no-js”的目的是什么?类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,在很多模板引擎中,在 HTML5 Boilerplate 中,在各种框架和纯php网站中在< HTML> 标签中添加了 no-js 类。

为什么这样做?是否有某种对此类反应的默认浏览器行为?为什么总是包括它?如果没有no-no-js的情况并且html可以直接写入,那么这不会导致类本身过时吗?

下面是HTML5 Boilerplate index.html:

 <! -  [if lt IE 7]> < html lang =enclass =no-js ie6>百分比抑制率ENDIF]  -  GT!; 
<! - [if IE 7]> < html lang =enclass =no-js ie7>百分比抑制率ENDIF] - GT!;
<! - [if IE 8]> < html lang =enclass =no-js ie8>百分比抑制率ENDIF] - GT!;
<! - [if IE 9]> < html lang =enclass =no-js ie9>百分比抑制率ENDIF] - GT!;
<! - [if(gt IE 9)|!(IE)]><! - > < html lang =enclass =no-js> <! - <![ENDIF] - GT;

正如您所见,< html> 元素将永远拥有这个类。
有人可以解释为什么经常这样做吗?

解决方案

当Modernizr运行时,它将删除no-js 类并用js替换它。这是根据是否启用Javascript支持应用不同CSS规则的一种方法。



请参阅 Modernizer的源代码


I notice that in a lot of template engines, in the HTML5 Boilerplate, in various frameworks and in plain php sites there is the no-js class added onto the <HTML> tag.

Why is this done? Is there some sort of default browser behavior that reacts to this class? Why include it always? Does that not render the class itself obsolete, if there is no no-"no-js" case and html can be addressed directly?

Here is an example from the HTML5 Boilerplate index.html:

<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
<!--[if IE 7 ]>    <html lang="en" class="no-js ie7"> <![endif]-->
<!--[if IE 8 ]>    <html lang="en" class="no-js ie8"> <![endif]-->
<!--[if IE 9 ]>    <html lang="en" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->

As you can see, the <html> element will always have this class. Can someone explain why this is done so often?

解决方案

When Modernizr runs, it removes the "no-js" class and replaces it with "js". This is a way to apply different CSS rules depending on whether or not Javascript support is enabled.

See Modernizer's source code.

这篇关于HTML“no-js”的目的是什么?类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆