var a = "alert( 111 )"
eval( a )

解决方案 »

  1.   

    The top-level function, eval, evaluates and/or executes a string of JavaScript code that is contained in the codestring argument. 
     
    First, eval determines if the argument is a valid string and then parses the string looking for JavaScript code. If there are JavaScript statements in the code, they will be executed and eval will return the value of the last statement (if there is a value). If there is a JavaScript expression, it will be evaluated and its value will be returned. 
     
    Note that the codestring argument is optional. However, if there is no argument, eval returned, "undefined". 
     
    Code: 
    eval("fred=999; wilma=777; document.write(fred + wilma);"); 
     
    Output: 
    1776