Example of using the Eval function in JS

Source: Internet
Author: User
Tags eval
The Eval function will use obj as code to execute it again, here is an example for you to introduce the specific method of using, interested friends can refer to ha, I hope to help you

eval (obj); The function executes obj as code.

Example:

Copy Code code as follows:


<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv=" Content-type " Content= "text/html; Charset=utf-8 "/>
<script src=" jquery-1.2.6.js "></script>
<title> eval function Use </title& Gt
<script>
Function But1_click () {
var obj = $ ("#test");
Alert (Obj.val ());
Eval (Obj.val ());//Obj.val () will be executed as code


</script>

<body>
<textarea id= "Test" cols= "rows=" >
var a = 3;
var b = 5;
var C = a + B;
Alert (c);
</textarea>
<input type= "button" id= "BUT1" value= "Execute" onclick= "But1_click ()"/>
</body>

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.