在XHTML中的noscript替代方案? [英] noscript alternative in XHTML?

查看:100
本文介绍了在XHTML中的noscript替代方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在HTML中我可以这样做:

 < noscript>< link href =css / stylenojs.css =stylesheettype =text / css/>< / noscript> 

在XHTML Transitional或Strict文档中是否存在兼容的方法?

解决方案

你给的例子在HTML和XHTML中都是无效的。没有当前的建议提供了一种方法来包含样式表,除非启用了脚本。



通常,您应该避免< ; NOSCRIPT> 。从有用的东西开始,然后构建它。 p>

在这种情况下,您可以为非JS客户端编写样式表,然后:

 <身体GT; 
< script type =text / javascript> document.body.className + ='js';< / script>

...并且包含额外的特定于JS的规则集:

  body.js foo {
}

或者,您可以执行以下操作:

 < link href =css / stylenojs.css rel =stylesheettype =text / cssid =nojscss/> 

  var nojscss = document.getElementById('nojscss'); 
nojscss.parentNode.removeChild(nojscss);


In HTML I could do:

<noscript><link href="css/stylenojs.css" rel="stylesheet" type="text/css" /></noscript>

Is there some compliant way to do so in XHTML Transitional or Strict documents?

解决方案

The example you give is invalid in HTML as well as XHTML. No current recommendation provides a way to include a stylesheet unless scripting is enabled.

In general, you should avoid <noscript>. Start with something that works, and then build on it.

In this case, you could write your stylesheet for non-JS clients, then:

<body>
<script type="text/javascript">document.body.className += ' js';</script>

… and include additional rule-sets specific to JS being enabled with:

body.js foo {
}

Alternatively, you could do something like:

<link href="css/stylenojs.css" rel="stylesheet" type="text/css" id="nojscss" />

and

var nojscss = document.getElementById('nojscss');
nojscss.parentNode.removeChild(nojscss);

这篇关于在XHTML中的noscript替代方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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