demo中不该先调用add()把,打开网页就直接弹出计算结果了。
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" <title>function</title> <script type="text/javascript"> function add2 (){ sum = 5 + 6; alert(sum); } //add2(); </script>> </head> <body> <form> <input type="button" value="click" onclick="add2()"> </form>> </body> </html>>