简体   繁体   English

无法从SITE.MASTER调用外部javascript函数

[英]Cannot call external javascript function from SITE.MASTER

I have a Site.Master in my ASP.NET project which defines a HEAD section as follows 我的ASP.NET项目中有一个Site.Master,它定义了HEAD部分,如下所示

<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title id="MasterTitle">MyApp</title>
    <link rel="icon" href="Content/icon.ico" type="image/x-icon" />
    <link href="Content/mycss.css" rel="stylesheet" type="text/css" />
    <script src="Content/mycode.js" type="text/javascript"></script>
</head>

In the mycode.js file, I have a function called GetSels(); 在mycode.js文件中,我有一个名为GetSels()的函数;

function GetSels()
{
//do stuff
}

If the GetSels function is defined in Site.Master, GetSels is callable. 如果在Site.Master中定义了GetSels函数,则可以调用GetSels。 If it's in mycode.js, it's not. 如果在mycode.js中,则不是。

Every code example I've seen seems to say this should work. 我见过的每个代码示例似乎都说这应该可行。

What am I doing wrong? 我究竟做错了什么?

This should really work perfectly as I have done this multiple times myself. 我本人已经多次这样做,所以它应该确实可以完美工作。

Check that the code in your external javascript file runs correctly on page load, this is just to make sure that it is indeed being loaded correctly into your document. 检查外部javascript文件中的代码在页面加载时是否正确运行,这只是为了确保确实将其正确加载到文档中。 For example set an alert("It's loaded"); 例如,设置一个警报(“已加载”); in your external .js file. 在您的外部.js文件中。

have you checked that your reference to mycode.js is correct? 您是否检查过对mycode.js的引用正确? if your using a relative path try "~/Content/mycode.js" in your reference. 如果您使用相对路径,请在参考中尝试“〜/ Content / mycode.js”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM