开发者

Including a javascript file inside a javascript function

I have a need to include a javascript file inside another javascript function. I dont have any html file. I am executing the javascript code inside a .NET program like this

                MSScriptControl.ScriptControl js = 开发者_JAVA技巧new MSScriptControl.ScriptControl();
                js.AllowUI = false;
                js.Language = "JScript";
                js.Reset();
                js.AddCode(@"
                function test(x)
                {
                  return x+10;
                }
                ");

I need to reference a javascript file inside the function test. Can someone help me out?

Thanks


There are no such instruction like 'include' in javascript language. So, to accomplish what you want you have to read another script content and concatinate it with the rest of code;

The code would be something like that:

var includedScript = ReadScriptFromFile("myfile.js");
var includedScript += @"function (x) { return x + 10";

js.AddCode(includedScript);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜