JavaScript 随机数记录demo
2016-06-08 13:39
211 查看
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>随机数记录</title> <script> // alert( Math.round(3.4) ); // 0~1 : Math.round(Math.random()); // 0~10 // alert( Math.round(Math.random()*10) ); // 5~10 // alert( Math.round( Math.random()*5 + 5 ) ); // 10~20 // alert( Math.round( Math.random()*10 + 10 ) ); // 20~100 // alert( Math.round( Math.random()*80 + 20 ) ); // x ~ y var x = 3; var y = 49; // alert( Math.round( Math.random()*(y-x) + x ) ); // 0~x // alert( Math.round( Math.random()*x) ); // 1~x alert( Math.ceil( Math.random()*x) ); // 课上小练习: // 随机产生 100 个从 0 ~ 1000 之间不重复的整数 // var str = 'aaasdlfjhasdlkfs'; // indexOf('s') —— 为数组编写该方法:indexOf('img/1.jpg') </script> </head> <body> </body> </html>
相关文章推荐
- JavaScript 排序demo
- ActiveX异步回调JavaScript(通过事件方式)
- JavaScript 组数去重demo
- C# JSon转换
- 理解闭包 js回收机制
- js公有、私有、静态属性和方法的区别
- [转]js中的逻辑与(&&)和逻辑或(||)
- 取余运算符 (%)
- JSON页面间传值问题
- javascript防篡改对象
- Javascript必知必会(四)js类型转换
- 【JavaScript】——兼容浏览器的居中显示+关闭页面
- 使用 Jsoup 爬虫解析 html 新闻的实例
- JavaScript必知必会(三) String .的方法来自何方
- 《JavaScript DOM 编程艺术》读书笔记
- JavaScript必知必会(二) null 和undefined
- js滚动失效
- JavaScript必知必会(九)function 说起 闭包问题
- javascript array拆分(合并)与简单应用(文字背景)demo
- javascript substring截取之收缩文本demo