这里写目录标题
jQuery1、判断函数2、字符串转换为数组3、查找数组中的元素4、数学5、获取窗口的宽高6、js时间格式方法7、在字符串前或后添加字符
jQuery
1、判断函数
isNaN($x
)
2、字符串转换为数组
一个字符串分割为子字符串,然后将结果作为字符串数组返回
var str
= "The rain in Spain falls mainly in the plain.";
var arr
= str
.split(" ");
3、查找数组中的元素
in_array('day',$arr
)
4、数学
Math
.round(0.60)
Math
.floor(0.60)
Math
.cell(0.60)
5、获取窗口的宽高
var winH
=$(window
).height();
var winW
=$(window
).width();
窗口改变时会触发该方法
$(window
).resize(function(){
});
或
$(window
).resize(方法名
);
6、js时间格式方法
function dateFtt(fmt
, date
) {
var o
= {
"M+": date
.getMonth() + 1,
"d+": date
.getDate(),
"h+": date
.getHours(),
"m+": date
.getMinutes(),
"s+": date
.getSeconds(),
"q+": Math
.floor((date
.getMonth() + 3) / 3),
"S": date
.getMilliseconds()
};
if (/(y+)/.test(fmt
))
fmt
= fmt
.replace(RegExp
.$
1, (date
.getFullYear() + "").substr(4 - RegExp
.$
1.length
));
for (var k
in o
)
if (new RegExp("(" + k
+ ")").test(fmt
))
fmt
= fmt
.replace(RegExp
.$
1, (RegExp
.$
1.length
== 1) ? (o
[k
]) : (("00" + o
[k
]).substr(("" + o
[k
]).length
)));
return fmt
;
}
7、在字符串前或后添加字符
前端开发中,会遇到字符串填充的问题,padStart()和padEnd()可能会有帮助: 使用指定字符串填充到目标字符串前面,使其达到目标长度;
str
.padStart(length
,string
):
使用指定字符串填充到目标字符串后面,使其达到目标长度;
str
.padEnd(length
,string
):