W3CAPI 实例工具箱
运行代码
源代码
<!DOCTYPE html> <head> <meta charset="utf-8" /> <title>js 示例</title> </head> <body> <script type="text/javascript"> function w3rfunction(){ 'use strict'; var x = document.getElementById("number").value; if(x < 2 || x > 10){ document.getElementById("result").innerHTML = "The number is not within the range."; } else { var z = 0; var y; for(y=1; y<=x; y++) { z = z + y; if(y===x) { break; } } document.getElementById("result").innerHTML = 'The sum of numbers between 1 to '+ x +' is: '+ z; } } </script> </body> </html>
运行结果
友情提示
您正在使用的浏览器为IE浏览器,或者使用了IE模式
如果你使用的是IE浏览器,建议您下载
360急速浏览器
/
火狐浏览器
/
Opera浏览器