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 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀