在我的HTML文件中,我已经链接到JS:
src="myscript.js?config=true"
Run Code Online (Sandbox Code Playgroud)
我的JS能直接读取这个var的值吗?
alert (config);
Run Code Online (Sandbox Code Playgroud)
这不起作用,FireFox错误控制台说"配置未定义".如何读取JS文件中通过src属性传递的变量?这很简单吗?
是否可以将变量传递给链接的.js文件?我试过这个:
<sf:JsFileLink ID="JQueryLoader" runat="server" ScriptType="Custom" FileName="~/Files/Scripts/rotatorLoader.js?timeout=1000" />
Run Code Online (Sandbox Code Playgroud)
但是萤火虫告诉我没有定义超时.这是.js文件的代码:
$(document).ready(function() {
$("#rotator > ul").tabs({ fx: { opacity: "toggle"} }).tabs("rotate", timeout, true);
});
Run Code Online (Sandbox Code Playgroud)
我正在使用<sf:JsFileLink ... />标签是因为我正在使用的网站使用sitefinity,这个标签允许我加载外部.js文件.
我能够通过创建一个模拟javascript页面的aspx页面来"欺骗"include:
<%@ Page Language="C#" %>
<%
Response.ContentType = "text/javascript";
Response.Clear();
string timeout;
try
{
timeout = Session["timeout"].ToString();
}
catch
{
timeout = "4000";
}
%>
$(document).ready(function() {
$("#rotator > ul").tabs({ fx: { opacity: "toggle"} }).tabs("rotate", <%=timeout %>, true);
});
Run Code Online (Sandbox Code Playgroud)
在用户控制页面上:
[DefaultProperty("BannerTimeout")]
public partial class Custom_UserControls_TabbedRotator : System.Web.UI.UserControl
{
[Category("Configuration")]
[Description("Sets the rotation timeout, …Run Code Online (Sandbox Code Playgroud) 您可以将键值对传递给JavaScript文件,如下所示:
<script type="text/javascript" src="http://www.example.com/script.js?key=value"></script>
Run Code Online (Sandbox Code Playgroud)