【JS学习笔记】内置对象

晓石头的博客
邮箱:[email protected]

转载请注明出处,原文链接:http://blog.csdn.net/qiulanzhu/article/details/50663564


//Global对象

//URI编码
var name = "//qiu 邱"

var encodeName = encodeURI(name);
var encodecompName = encodeURI(name);
document.write(encodeURI(name) +'<br>');
document.write(encodeURIComponent(name) +'<br>');

document.write(decodeURI(encodeName));
document.write(decodeURIComponent(encodeName));

//eval()方法
//担当一个字符串解析器的作用(常配合数据库使用)
eval('var box = 100');
document.write(box);


//Math对象
Math.E;
Math.LN10;
Math.LN2;
Math.LOG2E;
Math.LOG10E;
Math.PI;
Math.SQRT1_2;
Math.SQRT2;

Math.min(2,3);		//最小值
Math.max(2,3);		//最大值

Math.ceil(25.1);	//26:向上舍入
Math.floor(25.9);	//25:向下舍入
Math.round(25.5);	//26:四舍五入

//random():产生随机数
//参数lower 到 upper的随机数
function selectForm(lower, upper){
	var number = upper - lower + 1;
	return Math.floor(Math.random()*number + lower); 
}


你可能感兴趣的:(JavaScript,内置对象)