0

我无法从我的 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();"

我必须在这个连接中丢失一些东西,因为我无法在页面加载时触发警报

4

1 回答 1

0

如果用户是类的名称,那么您的脚本命令将是

scriptCommands=@"new User().UseThisNewThing();"

您不能在不创建类实例的情况下直接调用该函数

于 2012-08-21T18:41:16.757 回答