什么也不说了,一直再用,需要的直接复制过去
/// <summary>
/// 执行JS
/// </summary>
/// <param name="funcName">方法名</param>
/// <param name="argument">传入参数</param>
/// <param name="jsPath">JS文件路径</param>
/// <returns></returns>
public static object ExecuteScript(string funcName, string argument, string jsPath)
{
string js = System.IO.File.ReadAllText(jsPath);
object o = ExecuteScript(string.Format("{0}('{1}')", funcName, argument), js);
return o;
}
/// <summary>
/// 执行JS
/// </summary>
/// <param name="sExpression">参数体</param>
/// <param name="sCode">JavaScript代码的字符串</param>
/// <returns></returns>
public static object ExecuteScript(string sExpression, string sCode)
{
MSScriptControl.ScriptControl scriptControl = new MSScriptControl.ScriptControl();
scriptControl.UseSafeSubset = true;
scriptControl.Language = "JScript";
scriptControl.AddCode(sCode);
try
{
return scriptControl.Eval(sExpression);
}
catch (Exception ex)
{
}
return null;
}
网友评论