<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>自制计算器</title> <script src="add.js" type="text/javascript"></script> </head> <body> <div align="center" style="margin-top: 60px"> <img src="add.png"> </div> <div align="center" style="margin-top: 80px"> <form name="form1"> <input type="text" name="add1" placeholder="add1">+ <input type="text" name="add2" placeholder="add2">= <input type="text" readonly="readonly" name="result" placeholder="result"> <input type="button" name="submit" value="计算" onclick="add()"> </form> </div> </body> </html> /** * Created by Administrator on 2018/2/18. */ function add() { var add1 = Number(document.form1.add1.value); var add2 = Number(document.form1.add2.value); var result = add1 + add2 document.form1.result.value=result }