1

在 html 页面中,我们使用 head 标签来添加对外部 .js 文件的引用 .. 我们还可以在 body 中包含 script 标签 .. 但是我们如何在 Web 用户控件中包含我们的外部 .js 文件?

经过一番谷歌搜索,我得到了这个。它有效,但这是唯一的方法吗?

ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "MyUniquekey", @"<script src=""myJsFile.js"" type=""text/javascript""></script>", false);

——祖海布

4

3 回答 3

2

你也可以使用

Page.ClientScript.RegisterClientScriptInclude("key", "path/to/script.js");

这就是我一直这样做的方式

于 2008-11-11T08:29:55.543 回答
1

是的,这也有效.. 但是为什么所有脚本都被倾倒在身体而不是头脑中?

这里有一个潜在的解决方法

于 2008-11-11T09:48:15.277 回答
1

这有点不正确..关于在正文中需要 Javascript。

Javascript 函数将位于未执行的头部,并且完全不受元素仍要加载的事实的影响。

通常在页面末尾有一个调用来开始执行顶部的脚本。(其他方法可用)

The only reason that script gets dumped in the body, is because MS doesn't seem to give 2 hoots about JavaScript. Shame, because forcing us all to use .NET proper, just makes the world full of sluggish pages that needlessly run back and forth to servers for the tiniest requirmenet.

于 2011-07-19T14:06:40.557 回答