dongmei1828 2014-09-28 05:51
浏览 44
已采纳

我可以将IE条件放在functions.php - WordPress中

We are taught to place the following script in the <head> section, conditional to IE 9.

<!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

As in WordPress I tend to use wp_enqueue_script() to hook scripts to wp_head() (default) or wp_footer(). My question is:

(1) can we implement something like the following in functions.php in WordPress theme?

function project_scripts(){?>
  <!--[if lt IE 9]>
  <?php
     wp_enqueue_script( 'IE-scripts', 'http://html5shiv.googlecode.com/svn/trunk/html5.js' );
  ?>
  <![endif]-->
<?php
}
add_action( 'wp_enqueue_scripts', 'project_scripts' );

(2) If so, can I do it otherwise:

function project_scripts(){
  echo '<!--[if lt IE 9]>';
     wp_enqueue_script( 'IE-scripts', 'http://html5shiv.googlecode.com/svn/trunk/html5.js' );
  echo '<![endif]-->';
}
add_action( 'wp_enqueue_scripts', 'project_scripts' );
  • 写回答

1条回答 默认 最新

  • dongshan2680 2014-09-28 05:55
    关注

    No. JavaScript cannot include IE conditionals.

    This is because IE conditional are HTML comment nodes and, just as normal HTML markup makes no sense in JavaScript source, such comments result in invalid JavaScript.

    It may be worthwhile to look into an approach like Modernizr which utilizes feature detection. Alternatively, IE conditional can be used to add classes to an element which can be detected later, as shown here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器