Simply put, you can convert the string to an expression and return the execution result
eval method
Please see
String Object
Apply to: Global Object
Requirements
Version 1
Check JScript code and execute.
Eval (codestring)
Required codestring parameter is a string value that contains valid JScript code. This string will be parsed and executed by the JScript parser.
Description
The Eval function allows for dynamic execution of JScript source code. For example, the following code creates a new variable mydate that contains a Date object:
Eval ("var mydate = new Date ();");
The context passed to the Eval method's execution is the same as the call to the Eval method.
<script language= "JavaScript" > <!--var test = ' alert (' hi! ') '; Eval (test)//--> </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
Look at this case:
<textarea id="runcode30815"><div > Hide the following text </div> <div id= "Aa1" > Text </div> <div id= "Aa2" > Text two </div> <div i d= "Aa3" > Text three </div> <div id= "AA4" > Text four </div> take notes out of the run look at it. <script language= "JavaScript" > F Unction Hidediv (str) {for (i=1;i<=4;i++) {//(str+i). style.display= "None";//error writing, Layer//eval (str+i) cannot be hidden. Style.display= "None"; Write a return expression str+i the value alert (str+i+ ". style.display= ' None ') to JavaScript;/pop-up character channeling info eval (str+i+). Style.display= ' None ' "); Or so write the string directly by eval (the string must be compliant with JavaScript syntax), hide the text//This string will be parsed and executed by the JScript parser. The eval () function executes the expression represented by the string "Str+i", provided that the string must be an expression that is JavaScript-understandable, and the eval () function executes and returns the value of the string expression//aa1, Aa2, Aa3, AA4//Individual STR +i//document.getelementbyid (str+i). style.display= "None"; Quite with using this method}} </script></textarea>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]