JavaScript eval () Usage _javascript tips

Source: Internet
Author: User
Tags eval javascript eval
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]
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.