<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <img src="../image/desktop/1.jpg" width="200" height="100" name="aaa"/> <img src="../image/desktop/2.jpg" width="200" height="100" name="bbb"/> <img src="../image/desktop/3.jpg" width="200" height="100" name="ccc"/> <input type=‘button‘ value="chagne" onclick="changeImage()"/> <script> function changeImage() { var img_name = prompt("please enter your image name:",""); var img_str = "window.document."+img_name; var img_obj = eval(img_str); if(img_obj) img_obj.src = "../image/desktop/"+parseInt(Math.random()*27+1)+".jpg"; } </script> </body> </html>
var json = ‘{"response":"success","level":"ok"}‘; //result = eval(json);//eval会将{}当做语句块来处理,而不是对象 result = eval(‘(‘+json+‘)‘); alert(result);
result = (new Function("","return"+json))();
alert(result);
时间: 2024-11-20 13:36:51