8 <body> 10 <!-- 11 eval 的使用:eval(string) 12 计算某个字符串,并执行其中的js代码 13 14 字符串上运用 eval() 15 eval("x = 10;y = 2;document.write(x*y)"); 16 17 --> 18 <script> 19 eval("x =10;y=2;document.write(x*y)");//20 20 21 document.write(eval("2*2"));//4 22 23 var x = 10; 24 document.write(eval(x + 7));//17 25 26 // var myeval = eval;//易报错,不建议用 27 28 29 30 //!!!解析json字符串 31 var txt = '{ "userid": "11", "name": "liyi" }'; 32 var txtObj = eval("(" + txt + ")"); 33 document.write(txtObj.userid);//11 34 </script> 35 </body>