标签:
<!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> </body> </html> <script> var a=prompt("请输入一个整数","只能是整数"); if(a!=null) { var b=isNaN(a); if(b==false) { var c=parseInt(a); var sum=0; for(var i=1;i<=c;i++) { sum+=i; } alert(sum); } else { alert("输入有误!"); } } else { } </script>
<!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> 请输入一个数字:<input type="text" id="text"/> <input type="button" value="请点击" onclick="add()"/> </body> </html> <script> function add() { var a= document.getElementById("text"); var b=isNaN(a.value); if(b==false) { var c= parseInt(a.value); var sum=0; for(var i=0;i<=c;i++) { sum+=i; } document.write(sum); } else { alert("输入有误!"); } } </script>
标签:
原文地址:http://www.cnblogs.com/fengsantianya/p/5521300.html