1.uri方法
encodeuri()和encodeuricomponent()对uri进行编码
encodeuri()不会对本身属于uri的特殊字符进行编码,如冒号,正斜杠,问好,井字等
encodeuricomponent()会对任何非标准字符进行编码
2.eval() 方法:解释参数中的代码字符串
复制代码 代码如下:
var msg = hello world;
eval(alert(msg)); //hello world
3.math 对象
math.e 数学中的e的值
math.pi π的值
math.sqrt2 2的平方根
math.abs(num) num的绝对值
math.exp(num) e的num次幂
math.log(num) num的自然对数
math.pow(num,n) num的n次幂
math.sqrt(num) num的平方根
math.acos(x) x的反余弦值
math.asin(x) x的反正弦值
math.atan(x) x的反正切值
math.atan2(y,x) y/x的反正切值
math.cos(x) x的余弦值
math.sin(x) x的正弦值
math.tan(x) x的正切值
4.min()和max()方法
复制代码 代码如下:
var max = math.max(3,45,67,32);
alert(max); //67
var min = math.min(2,46,74);
alert(min); //2
5.小数舍入到整数方法
math.ceil() 向上舍入
math.floor() 向下舍入
math.round() 四舍五入
复制代码 代码如下:
alert(math.ceil(25.1)); //26
alert(math.ceil(25.5)); //26
alert(math.ceil(25.9)); //26
alert(math.round(25.1)); //25
alert(math.round(25.5)); //26
alert(math.round(25.9)); //26
alert(math.floor(25.1)); //25
alert(math.floor(25.5)); //25
alert(math.floor(25.9)); //25
6. random() 方法 返回 介于 0~1 的一个随机数,不包括0和1
在某一范围内取一个随机数公式:
随机数 = math.floor(math.random * 总数 + 第一个值) // 总数=第二个值 - 第一个值
复制代码 代码如下:
//取范围内随机数函数
function selectfrom(lowervalue,uppervalue) {
var count = uppervalue - lowervalue + 1;
return math.floor(math.random() * count +lowervalue);
}
var num = selectfrom(2,10);
alert(num); //介于2~10之间的数(包括2和10)