【问题标题】:How to disable a jQuery script if IE8如果 IE8,如何禁用 jQuery 脚本
【发布时间】:2013-10-26 16:58:30
【问题描述】:

我将我网站不同元素的所有 jQuery 代码放在一个名为 scripts.js 的文件中,但是如果用户使用 IE8,我希望禁用一段代码。这是我要禁用的:

    $(document).ready(function(){
 $('.parallax-block-1').parallax("50%", 0.1);
});

我到处查找,唯一发现的是在 html 代码中在 <script> </script> 之前放置一个 IF 条件注释,例如 - <!--[if !(IE 8)]><!-->,但由于我将所有内容都放在一个 js 文件中,因此 IF 语句将禁用里面的所有其他脚本。

希望我的问题有意义。 谢谢大家!

【问题讨论】:

  • 您使用的是哪个版本的 jQuery?
  • 我猜的最新版本(jQuery 1.10.2)
  • 您可以在不同的<script> 周围使用条件注释之前您的<script>,它设置了一个标志
  • 你的意思是 html 代码中的条件注释?
  • 您在页面中使用任何编程语言吗?

标签: jquery internet-explorer-8 javascript


【解决方案1】:

你可以使用<!--[if !(IE 8)]><!--><html>标签中插入一个类名,然后在你的js文件中你可以使用该类名来指定是否启用js功能。 例如: 在 html 文件中:

 <!--[if IE 8]> <html class="lt-ie9"> <![endif]--> /* Rendered in IE8 browser */
<!--[if gt IE 8]><!--> <html> <!--<![endif]--> /* Rendered in other browsers */

然后在你的 JS 文件中:

if ($("html.lt-ie9").length > 0) {
   //your functions or code that should work on all browsers except for IE8 goes here
}

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 2011-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 2012-05-18
    相关资源
    最近更新 更多