简体   繁体   English

jQuery - 如果Javascript被禁用怎么办?

[英]jQuery - What if Javascript is disabled?

I have some elements with display:none; 我有一些display:none;元素display:none; in the CSS and some jQuery that will fade them in on a delay. 在CSS和一些jQuery将延迟淡出他们。

How can I handle browsers that have javascript turned off? 如何处理关闭javascript的浏览器? Is there some way of using <noscript> to change those elements display values? 是否有某种方法可以使用<noscript>来更改这些元素的显示值?

You can't set a CSS value without a script, but you could have the default as being the visible state, and the first thing you do in the script is immediately set the elements to the non-visible state before fading them on. 您不能在没有脚本的情况下设置CSS值,但您可以将默认值设置为可见状态,并且您在脚本中执行的第一件事就是在将元素淡入之前立即将元素设置为不可见状态。

You could also look at CSS Animations http://www.w3.org/TR/css3-animations/ which don't require JavaScript, but they do need a modern-ish browser http://caniuse.com/css-animation 您还可以查看CSS动画http://www.w3.org/TR/css3-animations/ ,它们不需要JavaScript,但它们确实需要现代浏览器http://caniuse.com/css-animation

If you use modernizr, it will insert the class js into your <html> tag (if Javascript is running of course), and by having the html structure proposed by HTML5 boilerpate: 如果你使用modernizr,它会将类js插入到你的<html>标签中(如果Javascript正在运行),并且通过HTML5 boilerpate提出的html结构:

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

By default you will have <html class="no-js"> , and you could potentially have certain things (that you are worried about being exposed that normally JS hides) in your css to by default use it as a parent selector to hide it. 默认情况下,您将拥有<html class="no-js"> ,并且您可能会在css中将某些东西(您担心通常是JS隐藏)暴露在默认情况下将其用作隐藏的父选择器它。

.no-js .whatever, .no-js .someOtherStuff { display: none; } <!-- just an example -->

Set the css property to display the elements and then if javascript is enabled, use javascript to close / hide the elements. 设置css属性以显示元素,然后如果启用了javascript,则使用javascript关闭/隐藏元素。 However, I don't like doing this because the number of users with javascript enabled far out weighs users without javascript. 但是,我不喜欢这样做,因为启用了javascript的用户数远远超过没有javascript的用户。 You don't want to force the bulk of your users to wait for the page to load all the elements and then hide them when they have already had a peak at the content. 您不希望强制大部分用户等待页面加载所有元素,然后在内容已经达到峰值时隐藏它们。

You want the users that are actually using your webpage the way you designed it, to have the best experience they can. 您希望实际使用您网页的用户采用您设计的方式,以获得最佳体验。 The web is so feature rich in javascript, jquery and other libraries that the users without javascript are used to not getting the experience the web developer intended. 网络功能丰富的javascript,jquery和其他库,没有javascript的用户习惯于无法获得Web开发人员的预期体验。 If I feel that I really have a soft spot for the users without javascript, I will redirect them to to a static page. 如果我觉得我对没有javascript的用户真的很感兴趣,我会将它们重定向到一个静态页面。 Them and the web crawlers will have fun together. 他们和网络爬虫将一起玩得开心。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM