Type type = Type.GetTypeFromProgID("ScriptControl");//获取脚本对象 object obj = Activator.CreateInstance(type);//Type type.InvokeMember("Language", BindingFlags.SetProperty, null, obj, new object[] { "JScript" }); //设置语言类型 string resultStr = ""; try { type.InvokeMember("AddCode", BindingFlags.InvokeMethod, null, obj, new object[] {"function aa(){return document;}"});//添加JS代码 strJs.Replace("window","this") resultStr = type.InvokeMember("Eval", BindingFlags.InvokeMethod, null, obj, new object[] { "aa();"}).ToString();//执行JS } catch (TargetInvocationException targetEx) { if (targetEx.InnerException != null) { throw targetEx.InnerException; } }
提示 document未定义 这个要怎么处理才好