[英]Calling A Function In External Javascript Asp.Net
我无法从asp.net页面调用外部javascript函数
我有一个名为user.js的文件。
UseThisNewThing:function () {
alert("In Function External");
}
我的asp.net页面在head标签中引用了此文件。
<script src="Js/User.js" type="text/javascript"></script>
现在我想通过jquery调用此函数,所以在后面的代码中我有这个
if (page != null && !string.IsNullOrWhiteSpace(scriptName) && !string.IsNullOrWhiteSpace(scriptCommands))
{
Type parentType = page.GetType();
// Check to see if the include script exists already.
if (!page.ClientScript.IsStartupScriptRegistered(parentType, scriptName))
{
page.ClientScript.RegisterStartupScript(parentType, scriptName,
"<script type=\"text/javascript\">\njQuery(document).ready(function () {" + scriptCommands + "});</script>"); ;
}
}
其中parentType是this.Page, scriptName="InitPage",
和
scriptCommands=@"User.UseThisNewThing();"
我必须在此连接中添加一些内容,因为我无法在页面加载时收到提醒
如果用户是类名,那么您的scriptcommand将是
scriptCommands=@"new User().UseThisNewThing();"
您必须创建类的实例才能直接调用该函数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.