<html> <head> <title>声明一个自定义的函数</title> </head> <body> <script language="javascript"> <!-- function sum(n){ s = 0; for(i=1;i<=n;i++){ s+=i; } return s; } document.write("1~10相加的结果为:",sum(10),"<br>"); document.write("1~100相加的结果为:",sum(100)); //--> </script> </body> </html>