0

このシナリオではよくわからないことが2つあります

まず、この形式のJavaScriptがあります

function Allocate()
{
    this.Name = $("allocateName");
    this.AddAllocation = $("addAllocation");
    this.setCustom= $("setCustom");
}
... some other initializations here
Allocate.prototype.EnableAllocations = function() {

 this.enableAllAlloactions();
 this.setCustomAllocations();
}

これは単なる例ですが、これはJavascriptのある種のクラスですか?これはAllocate.jsというファイルにあります。

私の質問は次のとおりです。

でEnableAllocationsを呼び出すとしたら、Page.ClientScript.RegisterClientScriptBlock(...);どうすればよいですか?

4

1 に答える 1

0

Allocateオブジェクトをインスタンス化し、そのEnableAllocations関数を呼び出す必要があります。

  var alloc = new Allocate();
  alloc.EnableAllocations;

したがって、コードを使用して文字列を作成し、次のように渡すことができます。

  Page.ClientScript.RegisterClientScriptBlock("key",
     "var alloc = new Allocate();alloc.EnableAllocations;");
  • 注:this.GetType()。FullNameをキーとして使用できます。異なるスクリプトに同じキーを使用しないでください。

このメソッドは非推奨です。代わりにClientScriptManager.RegisterClientScriptBlockメソッドを使用してください(使用しているフレームワークのバージョンによって異なります)。

最後に、使用しているライブラリはわかりませんが、$()いくつかのライブラリからのものです。したがって、そのライブラリに依存し、また、などにも依存しallocateNameますaddAllocation

于 2012-05-25T00:28:57.057 に答える