Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在IE检查块中加载js文件_Javascript_Python_Pyramid_Fanstatic - Fatal编程技术网

Javascript 如何在IE检查块中加载js文件

Javascript 如何在IE检查块中加载js文件,javascript,python,pyramid,fanstatic,Javascript,Python,Pyramid,Fanstatic,我正在尝试使用fanstatic加载外部js文件。以下是我如何调用要加载的文件: <!--[if lt IE 9]> <% h.html5shiv.need() %> <![endif]--> 问题是,当我检查源文件时,js文件被添加到标记中,而不是IE if检查中 <head> <script type="text/javascript" src="html5shiv.js"></script> <

我正在尝试使用fanstatic加载外部js文件。以下是我如何调用要加载的文件:

<!--[if lt IE 9]>
<%
  h.html5shiv.need()
%>
<![endif]-->

问题是,当我检查源文件时,js文件被添加到标记中,而不是IE if检查中

<head>
  <script type="text/javascript" src="html5shiv.js"></script>
  <!--[if lt IE 9]>

  <![endif]-->
</head>


有没有办法强制fanstatic在IE if复选框中呈现此js文件?

您可以使用以下方法:

#import simple js renderer
from fanstatic.core import render_js

#define your custom renderer
def render_conditional_comment_js(url, condition = 'lt', version = '9'):
    return '<!--[if %s IE %s]>%s<![endif]-->' % (condition, version, render_js(url))

#create a library
jquery_lib_conditional = Library('jquery_con', 'lib') 

#use your custom renderer for render a specific resource
jquery_js_conditional = Resource(jquery_lib_conditional, 'jquery-1.9.1.js', renderer = render_conditional_comment_js)
#导入简单js渲染器
从fanstatic.core导入render_js
#定义自定义渲染器
def render_conditional_comment_js(url,condition='lt',version='9'):
返回“%”(条件、版本、渲染(url))
#创建库
jquery\u lib\u conditional=库('jquery\u con','lib')
#使用自定义渲染器渲染特定资源
jquery\u js\u conditional=Resource(jquery\u lib\u conditional,'jquery-1.9.1.js',renderer=render\u conditional\u comment\u js)