//加法函数 function jiafa(a,b){ var a=parseInt(document.getElementById("number1").value); //parseInt()把文本转为Int类型 var b=parseInt(document.getElementById("number2").value); var c=a+b; //减法、乘法、除法同理 document.getElementById("sum1").value=c; } </script> <p> <input type="text" id="number1" /> + <input type="text" id="number2" /> = <input type="text" id="sum1"/> <input type="button" value="计算" onclick="jiafa()" /> </p>效果如下(可试用):
+ =
原文:http://www.cnblogs.com/zhaofl/p/4412887.html