如何在ASP.net中包含外部js文件

时间:2015-04-19 19:01:31

标签: javascript c# asp.net

我尝试了主文件和aspx文件以及cs文件中的所有方法,但是我尝试的方法从不起作用:

<script type="text/javascript" src='<%=ResolveUrl("~/example3.js")%>'></script>

<script language="javascript" type="text/javascript" src="example3.js">


protected void Page_PreRender(object sender, EventArgs e)
    {
        var scriptManager = ScriptManager.GetCurrent(Page);

        if (scriptManager == null) return;

        scriptManager.Scripts.Add(new ScriptReference { Path = "~/Scripts/example3.js" });
        scriptManager.Scripts.Add(new ScriptReference { Path = "~/Scripts/jit.js" });
    }

1 个答案:

答案 0 :(得分:0)

请尝试ResolveClientUrl

<script type="text/javascript" src='<%=ResolveClientUrl("~/example3.js")%>'></script>

如果您仍然看不到它,请在运行后检查页面源(在IE中,从Alt - &gt; View - &gt; Source),搜索“example.js”并检查路径是如何解析的