1. String方法
toLowerCase();//转小写
toUpperCase();//转大写
split(delimiter);// 将字符串拆分
substr(startIndex, length);//从startIndex开始,取length个字符
substring(startIndex, endIndex);// 取从start到end间的字符,不包含end索引本身
indexOf(searchString, startIndex);
lastIndexOf(searchString, startIndex);
charAt(index);// 返回指定索引处的字符
replace(regex, newString);// 替换部分字串内容
如:replace中第一个参数可以是正则。
2. 数学方法
PI :3.1415926
abs(x);// 绝对值
acos(x);// 反余弦
cos(x);// 余弦
asin(x);// 反正弦
sin(x);// 正弦
atan(x);// 反正切
tan(x);// 正切
sqrt(x);// 取平方根
ceil(x);// 向上取整
floor(x);// 向下取整
exp(x);// 返回E^x值
pow(x,y);// 返回y^x值
max(x,y);// 取大值
min(x,y);// 取小值
random();// 返回0到1之间的随机数
round(x);// 四舍五入后取整
// 四舍五入保留N位小数(不是math函数)
toFixed(N);
如:
var v = 3.56;
v.toFixed(1);// 3.6
取随机数:
如:四舍五入