标签:
/**
* 生成36位GUID
* @returns
*/
function uuid() {
return ‘xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx‘.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c == ‘x‘ ? r : (r & 0x3 | 0x8);
return (v.toString(16)).toUpperCase();
});
}
/**
* 判断某个值是否为空
* @param v 传入值
* @returns {Boolean} true:空,false:非空
*/
function isNull(v) {
/**
* 判断变量是否空值 undefined, null, ‘‘, [], {} 均返回true,否则返回false
*/
switch (typeof v) {
case ‘undefined‘:
return true;
case ‘string‘:
if (null == v || "" == v) {
return true;
}
break;
case ‘object‘:
if (null === v)
return true;
if (undefined !== v.length && v.length == 0)
return true;
for ( var k in v) {
return false;
}
return true;
break;
}
return false;
}
/**
* 如果是isNull 情况下返回设定的默认值,非空集返回原值
*/
function isNullReturn(value, defaultValue) {
if (isNull(defaultValue))
defaultValue = "";
return isNull(value) ? defaultValue : value;
}
/**
* 计算第一个时间减去第二个时间(都是毫秒数)相差多少天、小时、分钟
* 返回天、小时、分钟数组
*/
function diffDDHHMM(bt, et) {
if (!bt || !et) {
return ‘‘;
}
var st = parseInt(bt);
var edt = parseInt(et);
if (st < 13855078430) {
st = st * 1000;
}
if (edt < 13855078430) {
edt = edt * 1000;
}
var ms = st - edt;
var d = parseInt(ms / (3600000 * 24));// 相差的天数
var h = parseInt((ms - (d * 3600000 * 24)) / (3600000));// 算出剩下的小时数
var mm = parseInt((ms - h * 3600000 - d * 3600000 * 24) / 60000);// 剩下的分钟数
// alert(‘相差:‘+d+‘天 ‘+h+‘小时 ‘+mm+‘ 分钟‘+(d*86400000+h*3600000+mm*60000));
var dd = {};
dd.dd = d;
dd.hh = h;
dd.mm = mm;
return dd;
}
/**
* 将毫秒时间转换为需要格式时间显示
* 格式写法范例:
* yyyy-MM-dd hh:mm:ss.S==>2006-07-02 08:09:04.423
* yyyy-M-d h:m:s.S==>2006-7-2 8:9:4.18
* yyyy年MM月dd日 hh:mm:ss==>2006年07月02日 08:09:04
* yyyy-MM-dd hh:mm:ss==>2006-07-02 08:09:04
*/
function convertTimetoDateStr(dt,format) {
if (!dt) {
return ‘‘;
}
dt = parseInt(dt);
if (dt < 13855078430) {
dt = dt * 1000;
}
var dtime = new Date(dt);
return dtime.Format(format);
}
/**
* 取消冒泡事件
* 调用例子:
*
* $(".voteCreaterImgArea").unbind("click").bind("click",function(e){
* stopBubble(e);//取消冒泡
* });
*
*/
function stopBubble(event) {
if (event || event.stopPropagation) {
event.stopPropagation();
} else {
window.event.CancelBubble = true;
}
}
/**
* 分享方法
* share_type:新浪:sina、人人网:renren、qq空间:qzone、qq:qq、
* title:标题
* content:分享内容
* url:分享URL地址
* pic分享图片的路径(可选)
*/
function sns_share_show(share_type, title, content, url, pic) {
var str = ‘‘;
if (share_type == ‘sina‘) {
if (‘object‘ === typeof content) {
content = content[‘sina‘];
}
if (content != ‘‘)
title = content.substr(0, 140);
//ralateUid:”, /**关联用户的UID,分享微博会@该用户(可选)*/
var pop_url = "http://service.weibo.com/share/share.php?appkey=8151414690522&title="
+ encodeURIComponent(title)
+ "&pic="
+ encodeURIComponent(pic)
+ "&url=" + encodeURIComponent(url) + "&ralateUid=8153708648980";
str = "window.open(‘"
+ pop_url
+ "‘,‘_blank‘,‘scrollbars=no,width=600,height=480,left=75,top=20,status=no,resizable=yes‘);"
} else if (share_type == ‘renren‘ || share_type == ‘xiaonei‘) {
if (‘object‘ === typeof title) {
title = title[‘renren‘];
}
if (‘object‘ === typeof content) {
content = content[‘renren‘];
}
var rrShareParam = {
resourceUrl : url,
pic : pic,
title : title,
description : content
};
// shareClick(rrShareParam);
} else if (share_type == ‘qzone‘ || share_type == ‘qq‘) {
if (‘object‘ === typeof title) {
title = title[‘qq‘];
}
if (‘object‘ === typeof content) {
content = content[‘qq‘];
}
str = "window.open(‘http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?title="
+ encodeURIComponent(title)
+ "&summary="
+ encodeURIComponent(content)
+ "&pics="
+ encodeURIComponent(pic)
+ "&site="
+ encodeURIComponent("蚂蜂窝")
+ "&url="
+ encodeURIComponent(url)
+ "‘,‘_blank‘,‘scrollbars=no,width=600,height=450,left=75,top=20,status=no,resizable=yes‘);"
} else
return false;
return str;
}
/**
* 根据给定的值返回字符串,过滤掉为空或为 undefined的情况
*/
function getString(value, defaultStr) {
if (defaultStr == null || defaultStr == ‘undefined‘) {
defaultStr = ‘‘;
}
if (value == null || value == ‘undefined‘ || value == ‘null‘) {
return defaultStr;
}
return value;
}
function setCookie(c_name, value, expiredays) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + expiredays);
document.cookie = c_name + "=" + escape(value)
+ ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
// 使用方法:setCookie(‘username‘,‘Darren‘,30)
}
function getCookie(c_name) {
if (document.cookie.length > 0) {
c_start = document.cookie.indexOf(c_name + "=");
if (c_start != -1) {
c_start = c_start + c_name.length + 1;
c_end = document.cookie.indexOf(";", c_start);
if (c_end == -1)
c_end = document.cookie.length;
return unescape(document.cookie.substring(c_start, c_end));
}
}
return "";
}
/**
* 将json对象转化为string
*/
function jsonToString(o) {
var arr = [];
var fmt = function(s) {
if (s == null || s == ‘‘) {
s = "";
}
if (typeof s == ‘object‘ && s != null)
return jsonToString(s);
return /^(string|number)$/.test(typeof s) ? ‘"‘ + s + ‘"‘ : s;
}
for ( var i in o) {
if (i == ‘getName‘)
continue;
arr.push(‘"‘ + i + ‘":‘ + fmt(o[i]));
}
return "{" + arr.join(",") + "}";
}
/**
* 从URL中获取参数值
*/
function getParameter(val) {
var re = new RegExp(val + "=([^&#]*)", "i")
var a = re.exec(location.href)
if (a == null)
return null;
return decodeURI(a[1]);
};
/**
* 字符串截取显示,默认截取字符串指定的长度,超出部分默认省略号替换
*/
String.prototype.cutOut = function(length, defaultStr) {
if (this == null || defaultStr == ‘undefined‘) {
return "";
}
var len = this.length;
if (len > length) {
return this.substring(0, length)
+ ((defaultStr == null || defaultStr == ‘undefined‘) ? "..."
: defaultStr);
} else {
return this;
}
};
/**
* 判断value是否为字母
*/
function checkletter(value) {
var Regx = /^[A-Za-z]+$/;
if (Regx.test(value)) {
return true;
} else {
return false;
}
}
/**
* 将给定的对象[JSON对象或集合]追加到集合中
* @param obj
* @returns {Array}
*/
Array.prototype.addAll = function(obj) {
if ($.isArray(obj)) {// 如果传入参数是数组,就将传入的数组追加到本数组后面
var len = obj.length;
for ( var i = 0; i < len; i++) {
this[this.length] = obj[i];
}
} else {
this[this.length] = obj;
}
return this;
}
/**
* 字符串长度 - 中文和全角符号为1;英文、数字和半角为0.5
* shortUrl:true:一个URL当作十个字长度计算
*/
var getLength = function(str, shortUrl) {
if (true == shortUrl) {
// 一个URL当作十个字长度计算
return Math
.ceil(str
.replace(
/((news|telnet|nttp|file|http|ftp|https):\/\/){1}(([-A-Za-z0-9]+(\.[-A-Za-z0-9]+)*(\.[-A-Za-z]{2,5}))|([0-9]{1,3}(\.[0-9]{1,3}){3}))(:[0-9]*)?(\/[-A-Za-z0-9_\$\.\+\!\*\(\),;:@&=\?\/~\#\%]*)*/ig,
‘xxxxxxxxxxxxxxxxxxxx‘).replace(/^\s+|\s+$/ig,
‘‘).replace(/[^\x00-\xff]/ig, ‘xx‘).length / 2);
} else {
return Math.ceil(str.replace(/^\s+|\s+$/ig, ‘‘).replace(
/[^\x00-\xff]/ig, ‘xx‘).length / 2);
}
};
/**
* 截取字符串
*/
var subStr = function(str, len) {
if (!str) {
return ‘‘;
}
len = len > 0 ? len * 2 : 280;
var count = 0;
// 计数:中文2字节,英文1字节
var temp = ‘‘;
// 临时字符串
for ( var i = 0; i < str.length; i++) {
if (str.charCodeAt(i) > 255) {
count += 2;
} else {
count++;
}
// 如果增加计数后长度大于限定长度,就直接返回临时字符串
if (count > len) {
return temp;
}
// 将当前内容加到临时字符串
temp += str.charAt(i);
}
return str;
};
/**
* 验证手机
*/
function isMobile(mobileNum) {
if (mobileNum == "") {
return false;
}
if (!mobileNum.match(/^(13[0-9]|15[0-9]|18[0-9])\d{8}$/)) {
return false;
}
return true;
}
/**
* 验证邮箱
*/
function isEmail(email) {
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (filter.test(email)) {
return true;
} else {
return false;
}
}
/**
* 传入毫秒级时间与当前时间比较还剩下多少天
*/
function compareDateToNow(time) {
var datetime = new Date(time);
var timestamp = Math.round(new Date().getTime());
var date3 = timestamp - datetime; // 时间差的毫秒数
if (date3 > 0) {
// 计算出相差天数
var date = Math.floor(date3 / (24 * 3600 * 1000));
if (date < 10) {
date = "0" + date;
}
} else {
date = "0";
}
return date;
}
/**
* 传入毫秒级时间与当前时间比较还剩下多少小时,除天数外
*/
function compareHourToNow(time) {
var datetime = new Date(time);
var timestamp = Math.round(new Date().getTime());
var date3 = timestamp - datetime; // 时间差的毫秒数
if (date3 > 0) {
// 计算出小时数
var leave1 = date3 % (24 * 3600 * 1000); // 计算天数后剩余的毫秒数
var hour = Math.floor(leave1 / (3600 * 1000));
if (hour < 10) {
hour = "0" + hour;
}
} else {
hour = "0";
}
return hour;
}
/**
* 传入毫秒级时间与当前时间比较还剩下多少分钟,除小时数外
*/
function compareMinuteToNow(time) {
var datetime = new Date(time);
var timestamp = Math.round(new Date().getTime());
var date3 = timestamp - datetime; // 时间差的毫秒数
if (date3 > 0) {
var leave1 = date3 % (24 * 3600 * 1000); // 计算天数后剩余的毫秒数
// 计算相差分钟数
var leave2 = leave1 % (3600 * 1000); // 计算小时数后剩余的毫秒数
var minutes = Math.floor(leave2 / (60 * 1000));
if (minutes < 10) {
minutes = "0" + minutes;
}
} else {
minutes = "0";
}
return minutes;
}
/**
* 获取n天之前毫秒级时间
*/
function getBeforeDayTime(day) {
var zdate=new Date();
var stime=zdate.getTime()-(day*24*60*60*1000);
//var edate=new Date(sdate-(day*24*60*60*1000)).format("yyyy-MM-dd");;
return stime;
}
/**
* 获取n天之后毫秒级时间
*/
function getAfterDayTime(day) {
var zdate=new Date();
var stime=zdate.getTime()+(day*24*60*60*1000);
//var edate=new Date(sdate-(day*24*60*60*1000)).format("yyyy-MM-dd");;
return stime;
}
/**
* post 异步提交
*/
function doPost(url, jpara, fn_callback, fn_error) {
if (typeof (fn_callback) != ‘function‘) {
fn_callback = function() {
};
}
if (typeof (fn_error) != ‘function‘) {
fn_error = function() {
};
}
$.ajax({
url : url,
type : "POST",
data : JSON.stringify(jpara),
success : function(jdata) {
fn_callback(jdata);
},
dataType : "json",
contentType : "application/json;charset=utf-8",
error : function(jdata) {
if (jdata.status == 600) {
fn_callback(jdata.responseJSON);
} else {
fn_error(jdata);
}
}
});
}
/**
* get ajax 异步提交
*/
function doGet(url, jpara, fn_callback, fn_error) {
if (typeof (fn_callback) != ‘function‘) {
fn_callback = function() {
};
}
if (typeof (fn_error) != ‘function‘) {
fn_error = function() {
};
}
var names = ‘‘;
if (!isNull(jpara)) {
for ( var name in jpara) {
names += name + "=" + jpara[name] + "&";
}
names = names.substring(0, names.length - 1);
}
if (names.length > 0) {
url = url.indexOf("?") > 0 ? url + "&" + names : url + "?" + names;
}
$.ajax({
url : url,
type : "GET",
// data: JSON.stringify(jpara),
success : function(jdata) {
fn_callback(jdata);
},
dataType : "json",
contentType : "application/json;charset=utf-8",
error : function(jdata) {
if (jdata.status == 600) {
fn_callback(jdata.responseJSON);
} else {
fn_error(jdata);
}
}
});
}
/**
* post ajax 异步提交
*/
function doAjax(method, url, jpara, fn_callback, fn_error) {
if (typeof (fn_callback) != ‘function‘) {
fn_callback = function() {
};
}
if (typeof (fn_error) != ‘function‘) {
fn_error = function() {
};
}
$.ajax({
url : url,
type : method,
data : JSON.stringify(jpara),
success : function(jdata) {
fn_callback(jdata);
},
dataType : "json",
contentType : "application/json;charset=utf-8",
error : function(jdata) {
fn_error(jdata);
}
});
};
// doT模板初始化参数
var tmplOptions = {
evaluate : /\{\{([\s\S]+?\}?)\}\}/g,
interpolate : /\{\{=([\s\S]+?)\}\}/g,
encode : /\{\{!([\s\S]+?)\}\}/g,
use : /\{\{#([\s\S]+?)\}\}/g,
useParams : /(^|[^\w$])def(?:\.|\[[\‘\"])([\w$\.]+)(?:[\‘\"]\])?\s*\:\s*([\w$\.]+|\"[^\"]+\"|\‘[^\‘]+\‘|\{[^\}]+\})/g,
define : /\{\{##\s*([\w\.$]+)\s*(\:|=)([\s\S]+?)#\}\}/g,
defineParams : /^\s*([\w$]+):([\s\S]+)/,
conditional : /\{\{\?(\?)?\s*([\s\S]*?)\s*\}\}/g,
iterate : /\{\{~\s*(?:\}\}|([\s\S]+?)\s*\:\s*([\w$]+)\s*(?:\:\s*([\w$]+))?\s*\}\})/g,
varname : ‘it‘,
strip : true,
append : true,
selfcontained : false
};
// doT模板引擎与jquery集成
$.extend({
tmpl : function(template, options) {
options = (options) ? $.extend(tmplOptions, options) : tmplOptions;
return doT.template.apply(null, [ template, options ]);
}
});
/**
* 将以逗号分隔多图片转成list
*/
function convertImgsToList(imgs) {
//isNull(img) ? ‘images/default/person.png‘ : IMGBASEPATH + img;
return imgs.split(",");
};
/**
* 将form表单数据转化为json
*/
$.fn.serializeObject = function() {
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [ o[this.name] ];
}
o[this.name].push(this.value || ‘‘);
} else {
o[this.name] = this.value || ‘‘;
}
});
return o;
};
/**
* 分割字符
*/
function stringSplits(string, splits) {
if (isNull(string))
return [];
if (!isNull(splits)) {
return string.split(splits);
} else {
return [];
}
};
/**
* 操作提交按钮(防止重复提交) (obj:点击提交对象;clickword:点击后显示字)
*/
function unbindClickButton(obj, clickword) {
if (isNull(obj))
return false;
clickword = isNull(clickword) ? "提交中" : clickword;
// 撤销click事件
$(obj).unbind("click");
// 颜色变灰
$(obj).removeClass("bgcl_3").addClass("bgcl_11");
// 字样修改
$(obj).children().text(clickword);
};
/**
* 获取上传文件类型
*
* @param fileName
* @returns
*/
function getFileType(fileName) {
var FILETYPE = [];
FILETYPE[0] = [ ‘xls‘, ‘xlsx‘, ‘xlt‘ ];
FILETYPE[1] = [ ‘doc‘, ‘docx‘, ‘dot‘, ‘wps‘, ‘odt‘ ];
FILETYPE[2] = [ ‘ppt‘ ];
FILETYPE[3] = [ ‘rar‘, ‘zip‘ ];
FILETYPE[4] = [ ‘pdf‘ ];
FILETYPE[5] = [ ‘jpg‘, ‘bmp‘, ‘png‘, ‘jpeg‘, ‘tiff‘, ‘gif‘, ‘pcx‘, ‘tga‘,
‘exif‘, ‘fpx‘, ‘svg‘, ‘psd‘, ‘cdr‘, ‘pcd‘, ‘dxf‘, ‘ufo‘, ‘eps‘,
‘ai‘, ‘raw‘ ];
var ldot = fileName.lastIndexOf(".");
var type = fileName.substring(ldot + 1);
type = type.toLowerCase();
for ( var i = 0; i < FILETYPE.length; i++) {
for ( var j = 0; j < FILETYPE[i].length; j++) {
if (FILETYPE[i][j] == type) {
return FILETYPE[i][0];
}
}
}
return ‘other‘;
}
/**
* 检测身份证号码 return {state:true,message:"验证通过!"};
*/
function checkIdcard(idcard) {
var Errors = new Array("验证通过!", "身份证号码位数不对!", "身份证号码出生日期超出范围或含有非法字符!",
"身份证号码校验错误!", "身份证地区非法!");
var area = {
11 : "北京",
12 : "天津",
13 : "河北",
14 : "山西",
15 : "内蒙古",
21 : "辽宁",
22 : "吉林",
23 : "黑龙江",
31 : "上海",
32 : "江苏",
33 : "浙江",
34 : "安徽",
35 : "福建",
36 : "江西",
37 : "山东",
41 : "河南",
42 : "湖北",
43 : "湖南",
44 : "广东",
45 : "广西",
46 : "海南",
50 : "重庆",
51 : "四川",
52 : "贵州",
53 : "云南",
54 : "西藏",
61 : "陕西",
62 : "甘肃",
63 : "青海",
64 : "宁夏",
65 : "新疆",
71 : "台湾",
81 : "香港",
82 : "澳门",
91 : "国外"
};
var idcard, Y, JYM;
var S, M;
var idcard_array = new Array();
idcard_array = idcard.split("");
// 地区检验
if (area[parseInt(idcard.substr(0, 2))] == null)
return {
state : false,
message : Errors[4]
};
// 身份号码位数及格式检验
switch (idcard.length) {
case 15:
if ((parseInt(idcard.substr(6, 2)) + 1900) % 4 == 0
|| ((parseInt(idcard.substr(6, 2)) + 1900) % 100 == 0 && (parseInt(idcard
.substr(6, 2)) + 1900) % 4 == 0)) {
ereg = /^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/;// 测试出生日期的合法性
} else {
ereg = /^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;// 测试出生日期的合法性
}
if (ereg.test(idcard)) {
return {
state : true,
message : Errors[0]
};
} else {
return {
state : false,
message : Errors[2]
};
}
break;
case 18:
// 18位身份号码检测
// 出生日期的合法性检查
// 闰年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))
// 平年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))
if (parseInt(idcard.substr(6, 4)) % 4 == 0
|| (parseInt(idcard.substr(6, 4)) % 100 == 0 && parseInt(idcard
.substr(6, 4)) % 4 == 0)) {
ereg = /^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/;// 闰年出生日期的合法性正则表达式
} else {
ereg = /^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/;// 平年出生日期的合法性正则表达式
}
if (ereg.test(idcard)) {// 测试出生日期的合法性
// 计算校验位
S = (parseInt(idcard_array[0]) + parseInt(idcard_array[10])) * 7
+ (parseInt(idcard_array[1]) + parseInt(idcard_array[11]))
* 9
+ (parseInt(idcard_array[2]) + parseInt(idcard_array[12]))
* 10
+ (parseInt(idcard_array[3]) + parseInt(idcard_array[13]))
* 5
+ (parseInt(idcard_array[4]) + parseInt(idcard_array[14]))
* 8
+ (parseInt(idcard_array[5]) + parseInt(idcard_array[15]))
* 4
+ (parseInt(idcard_array[6]) + parseInt(idcard_array[16]))
* 2 + parseInt(idcard_array[7]) * 1
+ parseInt(idcard_array[8]) * 6 + parseInt(idcard_array[9])
* 3;
Y = S % 11;
M = "F";
JYM = "10X98765432";
M = JYM.substr(Y, 1);// 判断校验位
if (M == idcard_array[17]) {
return {
state : true,
message : Errors[0]
}; // 检测ID的校验位
} else {
return {
state : false,
message : Errors[3]
};
}
} else {
return {
state : false,
message : Errors[2]
};
}
break;
default:
return {
state : false,
message : Errors[1]
};
break;
}
}
// 滚动条是否到底部 (bottomPx:为距离底部多少像素)
function windowBottom(fn,bottomPx) {
if(isNull(bottomPx)) bottomPx = 5;
$(window).bind(
"scroll",
function() {
// 然后判断窗口的滚动条是否接近页面底部,这里的bottomPx可以自定义
if ($(document).scrollTop() + $(window).height() > $(document)
.height() - bottomPx) {
if (fn) {
fn();
}
}
});
}
//判断客户端类型
var clientType = {
userAgentInfo:navigator.userAgent,
mobileList:new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"),
checkType:function(client){
if(isNull(client)) return false;
if(typeof client == "string"){
var flag = false;
if(this.userAgentInfo.indexOf(client) > 0){
flag = true;
}
return flag;
}
},
isAndroid:function(){
var flag = this.checkType("Android");
return flag;
},
isIphone:function(){
var flag = this.checkType("iPhone");
return flag;
},
isIpad:function(){
var flag = this.checkType("iPad");
return flag;
},
isWinPhone:function(){
var flag = this.checkType("Windows Phone");
return flag;
},
isPC:function(){
var flag = true;
for (var v = 0; v < this.mobileList.length; v++) {
if (this.userAgentInfo.indexOf(this.mobileList[v]) > 0) { flag = false; break; }
}
return flag;
}
};
String.prototype.trim=function()
{
return this.replace(/(^\s*)|(\s*$)/g, ‘‘);
}
//字符串安全转义(避免恶意代码)
String.prototype.safeEscape = function() {
return this.replaceAll("<", "<").replaceAll(">", ">").replaceAll(
"\"", """).replaceAll(" ", " ");
}
//字符串文本里的超链接字符转换成可点击的网站(支持www,http,https开头网址)
String.prototype.httpHtml = function() {
var reg = /(http:\/\/|https:\/\/|www\.)((\w|=|\?|\.|\/|&|-)+)/g;
var replaceStr = (this[0] + this[1] + this[2] + this[3] == "www.") ? ‘<a target="_blank" href="http://$1$2">$1$2</a>‘
: ‘<a target="_blank" href="$1$2">$1$2</a>‘;
return this.replace(reg, replaceStr);
}
标签:
原文地址:http://my.oschina.net/u/2322635/blog/382931