Type obj = Type.GetTypeFromProgID("ScriptControl");
if (obj == null) return; //单身? 找不到对象啊,
object ScriptControl = Activator.CreateInstance(obj);
obj.InvokeMember("Language", BindingFlags.SetProperty, null, ScriptControl, new object[] { "JScript" });
string js = "function time(){return new Date().getTime()}";
obj.InvokeMember("AddCode", BindingFlags.InvokeMethod, null, ScriptControl, new object[] { js });
string str = obj.InvokeMember("Eval", BindingFlags.InvokeMethod, null, ScriptControl, new object[] { "time()" }).ToString();
textBox1.Text = str;
Type obj = Type.GetTypeFromProgID("ScriptControl");
if (obj == null) return; //单身? 找不到对象啊,
object ScriptControl = Activator.CreateInstance(obj);
obj.InvokeMember("Language", BindingFlags.SetProperty, null, ScriptControl, new object[] { "JScript" });
string js = "function random(){return Math.random()}";
obj.InvokeMember("AddCode", BindingFlags.InvokeMethod, null, ScriptControl, new object[] { js });
string str = obj.InvokeMember("Eval", BindingFlags.InvokeMethod, null, ScriptControl, new object[] { "random()" }).ToString();
textBox1.Text = str;
Type obj = Type.GetTypeFromProgID("ScriptControl");
if (obj == null) return; //单身? 找不到对象啊,
object ScriptControl = Activator.CreateInstance(obj);
obj.InvokeMember("Language", BindingFlags.SetProperty, null, ScriptControl, new object[] { "JScript" });
string str = obj.InvokeMember("Eval", BindingFlags.InvokeMethod, null, ScriptControl, new object[] { "(5*10-2*10)/2" }).ToString();
textBox1.Text = "(5*10-2*10)/2=" + str;
StringBuilder sb = new StringBuilder();
sb.Append("function getGtk(str) {");
sb.Append("var hash = 5381;");
sb.Append("for (var i = 0,");
sb.Append("len = str.length; i < len; ++i) {");
sb.Append(" hash += (hash << 5) + str.charAt(i).charCodeAt();");
sb.Append("}");
sb.Append("return hash & 0x7fffffff;");
sb.Append("}");
Type obj = Type.GetTypeFromProgID("ScriptControl");
if (obj == null) return; //单身? 找不到对象啊,
object ScriptControl = Activator.CreateInstance(obj);
obj.InvokeMember("Language", BindingFlags.SetProperty, null, ScriptControl, new object[] { "JScript" });
obj.InvokeMember("AddCode", BindingFlags.InvokeMethod, null, ScriptControl, new object[] { sb.ToString() });
string str = obj.InvokeMember("Eval", BindingFlags.InvokeMethod, null, ScriptControl, new object[] { "getGtk(\"123\")" }).ToString();
textBox1.Text = str;
string a="hello world";
BENKYY 发表于 2014-9-16 00:12
是不是所有的js都可以按照这个套路来?
QQ716774 发表于 2014-9-16 01:55
是的亲,只要是JS都没问题
欢迎光临 苏飞论坛 (http://www.sufeinet.com/) | Powered by Discuz! X3.4 |