0

asp.net ページから外部の JavaScript 関数を呼び出すのに問題があります

私はこれを持っているuser.jsというファイルを持っています..

 UseThisNewThing:function () {
 alert("In Function External");
 }

私のasp.netページは、ヘッドタグでこのファイルを参照しています..

<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 に答える