如何在IE check b中加载js文件

2024-05-16 13:31:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用fanstatic加载外部js文件。我这样调用要加载的文件:

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

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

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

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

有没有办法强制fanstatic在IE if检查块中呈现这个js文件?你知道吗


Tags: 文件标记ltifchecktypejsscript
1条回答
网友
1楼 · 发布于 2024-05-16 13:31:04

您可以使用以下选项:

#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)

相关问题 更多 >