//判断页面加载完毕
document.onreadystatechange = function () {
if (document.readyState == "complete") {
//code...
}
}
//判断是否全为手机
String.prototype.isMobile = function () {
var pattern = /^0{0,1}(13[0-9]|14[6|7]|15[0-3]|15[5-9]|18[0-3]|18[5-9])[0-9]{8}$/;
return pattern.test(this);
}
//判断是否全为中文
String.prototype.isChinese = function () {
var pattern = /^[\u4e00-\u9fa5]+$/;
return pattern.test(this);
}
//判断是否全为英文
String.prototype.isEnglish = function () {
var pattern = /^[a-zA-Z]+$/;
return pattern.test(this);
}
//判断是否为空
String.prototype.isEmpty = function () {
var _this = this;
if (_this == "")
return true;
}
//清除空格
String.prototype.Trim = function () {
return this.replace(/(^\s*)|(\s*$)/g, "");
}
/* 检测级数中是否包含此项
var ar = ["a", "b"];
if (ar.contains("a"))
alert("true"); //结果:true
*/
Array.prototype.contains = function (element) {
for (var i = 0; i < this.length; i++) {
if (this[i] == element) {
return true;
}
}
return false;
}