<!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" /> <script src="jquery-1.2.6.js" ></script> <title> eval 函数的使用 </title> </head> <script> function but1_click(){ var obj = $("#test"); alert(obj.val()); eval (obj.val());//会将 obj.val() 当成代码去执行 }
</script>
<body> <textarea id="test" cols="100" rows="10" > var a = 3; var b = 5; var c = a + b; alert(c); </textarea> <input type="button" id="but1" value="执行" onclick="but1_click()" /> </body> </html>