<!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>
<title>6-1</title>
</head>
<body><!--用户界面,包括三个文本框,一个按钮-->
<input id="t1" type="text" style="width:50px height:20px"/>+<input id="t2" type="text" style="width:50px height:20px"/>=<input id="t3" type="text" style="width:50px height:20px"/> <input id="b" type="button" value="计算" onclick="sum()"/><script language="javascript">
var arg1=document.getElementById("t1");
var arg2=document.getElementById("t2");
var arg=document.getElementById("t3");
function sum(){
var a=arg1.value;
var b=arg2.value;
var s=new Function("sum(a,b)","return a+b");
//alert(s);
arg.value=s;
}
</script> </body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>6-1</title>
</head>
<body><!--用户界面,包括三个文本框,一个按钮-->
<input id="t1" type="text" style="width:50px height:20px"/>+<input id="t2" type="text" style="width:50px height:20px"/>=<input id="t3" type="text" style="width:50px height:20px"/> <input id="b" type="button" value="计算" onclick="sum()"/><script language="javascript">
var arg1=document.getElementById("t1");
var arg2=document.getElementById("t2");
var arg=document.getElementById("t3");
function sum(){
var a=arg1.value;
var b=arg2.value;
var s=new Function("sum(a,b)","return a+b");
//alert(s);
arg.value=s;
}
</script> </body>
</html>
var arg2=document.getElementById("t2");
var arg=document.getElementById("t3");
function sum(){
var a=parseInt(arg1.value);
var b=parseInt(arg2.value);
s = a + b;
arg.value=s;
}
我的这个是多余的吗?
看一下Function对象的说明:http://www.w3school.com.cn/js/pro_js_functions_function_object.asp