JavaScript禁用时如何隐藏HTML部分? [英] How to hide parts of HTML when JavaScript is disabled?

查看:76
本文介绍了JavaScript禁用时如何隐藏HTML部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在没有JavaScript的情况下适应用户。 (顺便说一句,现在是否值得付出努力?)



在一个HTML文件中,如果脚本在,另一部分是脚本关闭。



< noscript> 标签让我可以做前者,但如何实现后者?我如何标记HTML的一部分,以便在脚本 off 时不被浏览器解析解析方案

以下是关于如何使用jQuery完成的视频教程: http://screenr.com/ya7



代码:
$ b

 < ; body class =noscript> 
< script>
$('body')。removeClass('noscript');
< / script>
< / body>

然后隐藏 body.noscript

但是,JQuery可能会因为像这样的小修补而变得臃肿,所以我建议因为它不需要JQuery,所以Zauber Paracelsus的答案就是这样。


I'm trying to accommodate users without JavaScript. (By the way, is it worth the effort nowadays?)

In one HTML file I'd like part of it execute if scripts are on, and another part if scripts are OFF.

The <noscript> tag lets me do the former, but how to achieve the latter? How can I mark a part of HTML so that it is not parsed by browser if scripts are off?

解决方案

here's a video tutorial on how this can be done with jQuery: http://screenr.com/ya7

Code:

<body class="noscript">
<script>
$('body').removeClass('noscript');
</script>
</body>

And then just hide the relevant elements under body.noscript accordingly.

edit However, JQuery might be bloated for a small fix like this one, so I suggest Zauber Paracelsus' answer since it does not require JQuery.

这篇关于JavaScript禁用时如何隐藏HTML部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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