<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
function run(){
var p1=document.getElementById("param1").value;//将形参插入p1
var p2=document.getElementById("param2").value;
var p3=document.getElementById("param3").value;
var a1=document.getElementById("arg1").value;//将实参插入a1
var a2=document.getElementById("arg2").value;
var a3=document.getElementById("arg3").value;
var body=document.getElementById("funBody").value;//将函数体载入body
var testFun=new Function(p1,p2,p3,body);//创建函数对象
var result=testFun(a1,a2,a3);//调用函数
var def =document.getElementById('funDef');
def.innerHTML=testFun.toString();//输出整个函数
var _result=document.getElementById("returnValue");
_result.innerHTML=result;
}
</script>
</head>
<body style="font-size: 12px;">
<table>
<tr align="left">
<td>形参</td>
<td>
<input type="text" id="param1" size="3"/>
<input type="text" id="param2" size="3"/>
<input type="text" id="param3" size="3"/>
</td>
</tr>
<tr align="left">
<td>实参</td>
<td>
<input type="text" id="arg1" size="3"/>
<input type="text" id="arg2" size="3"/>
<input type="text" id="arg3" size="3"/></td>
</tr>
<tr align ="left">
<td>函数体</td>
<td><textarea id="funBody"></textarea></td>
</tr>
<tr align="left">
<td>函数测试</td>
<td><span id="funDef"></span></td>
</tr>
<tr align="left">
<td>函数返回结果</td>
<td><b><span id="returnValue"></span></b></td>
</tr>
</table>
<input type="button" value="运行函数" onclick="run()"/>
</body>
</html>