首页 > Web开发 > 详细

随机函数与JSON

时间:2017-12-04 11:14:22      阅读:285      评论:0      收藏:0      [点我收藏+]

1.随机函数

//随机函数
//Math.round() 四舍五入
Math.round(Math.random());//区0-1之间的整数即0或1
//0~10之间的整数
Math.round( Math.random()*10);
//5~10之间的整数
Math.round( Math.random()*5+5);
//20~100之间的整数
Math.round( Math.random()*80+20);
//x~y之间的整数
Math.round( Math.random()*(y-x)+x);
//0~x之间的整数
Math.round( Math.random()*x);
//1~x
Math.ceil( Math.random()*x);

2.JSON

var json={"name":"leo","age":24};
json.name;//leo
json["nume"];//leo

var imgData={
	imgUrl:["img/1.png","img/2.png","img/3.png","img/4.png"],
	txt:["图片一","图片二","图片三","图片四"]
}
imgData.imgUrl[0];//img/1.png

//json遍历
var json1={‘name‘:‘carol‘,‘age‘:18,‘fun‘:‘moile‘};
for (var attr1 in json1) {
//	alert(attr1);
	alert(json1[attr1]);
}

  

随机函数与JSON

原文:http://www.cnblogs.com/yangxue72/p/7975819.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!