【发布时间】:2021-11-01 07:56:23
【问题描述】:
我对 asp.net 网络表单很陌生,我想在我的母版页中添加一个包含 jquery 代码的 javascript 文件。
<body>
<form runat="server">
<asp:ScriptManager runat="server">
<Scripts>
<%--To learn more about bundling scripts in ScriptManager see https://go.microsoft.com/fwlink/?LinkID=301884 --%>
<%--Framework Scripts--%>
<asp:ScriptReference Name="MsAjaxBundle" />
<asp:ScriptReference Name="jquery" />
<asp:ScriptReference Name="bootstrap" />
<asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
<asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
<asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
<asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
<asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
<asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" />
<asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
<asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
<asp:ScriptReference Name="WebFormsBundle" />
<%--Site Scripts--%>
<script runat="server" src="Scripts/MyScripts/LogicMain.js"></script>
</Scripts>
</asp:ScriptManager>
LogicMain.js 是我想要包含在母版页中的文件,因为它会在加载的每个页面上运行。
更新: 我尝试只将 alert() 放在 .js 文件中,但它现在给出了一些其他错误。
【问题讨论】:
-
语法看起来不正确......也可能在它之前。使用类似: $( "#homeLogo" ).mouseenter(function() { .... (在您的帖子中包含更完整的 JS 代码)
-
您不能对 JavaScript 文件执行 runat="server"。 Web 窗体中的 JavaScript 在客户端上运行。
标签: asp.net webforms asp.net-webpages