/*------------------------------------------------------------
Trim()去左右空格
------------------------------------------------------------*/
String.prototype.Trim = function() {
return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.LTrim = function() {
return this.replace(/(^\s*)/g, "");
}
String.prototype.Rtrim = function() {
return this.replace(/(\s*$)/g, "");
}
/*------------------------------------------------------------
截取字符串,中文2个字符,英文1个字符
------------------------------------------------------------*/
function subString(str, len, hasDot) {
var newLength = 0;
var newStr = "";
var chineseRegex = /[^\x00-\xff]/g;
var singleChar = "";
var strLength = str.replace(chineseRegex, "**").length;
for (var i = 0; i < strLength; i++) {
singleChar = str.charAt(i).toString();
if (singleChar.match(chineseRegex) != null) {
newLength += 2;
}
else {
newLength++;
}
if (newLength > len) {
break;
}
newStr += singleChar;
}
if (hasDot && strLength > len) {
newStr += "...";
}
return newStr;
}
/*------------------------------------------------------------
replaceAll全部替换
------------------------------------------------------------*/
String.prototype.replaceAll = function(s1, s2) {
return this.replace(new RegExp(s1, "gm"), s2);
}
/*------------------------------------------------------------
不区分大小写的 javascript indexOf
兼容原来的 indexOf
------------------------------------------------------------*/
String.prototype._indexOf = String.prototype.indexOf;
String.prototype.indexOf = function() {
if (typeof (arguments[arguments.length - 1]) != 'boolean')
return this._indexOf.apply(this, arguments);
else {
var bi = arguments[arguments.length - 1];
var thisObj = this;
var idx = 0;
if (typeof (arguments[arguments.length - 2]) == 'number') {
idx = arguments[arguments.length - 2];
thisObj = this.substr(idx);
}
var re = new RegExp(arguments[0], bi ? 'i' : '');
var r = thisObj.match(re);
return r == null ? -1 : r.index + idx;
}
}
/*------------------------------------------------------------
过滤HTML标记
------------------------------------------------------------*/
function fliterHTML(sTest) {
var reTag = /<(?:.|\s)*?>/g;
var a = sTest.replace(reTag, "");
return a;
}
/*------------------------------------------------------------
兼容FF的previousSibling
------------------------------------------------------------*/
function previousElementSibling(lipre) {
try {
do {
lipre = lipre.previousSibling;
if (!lipre) return null;
} while (lipre.nodeType != 1)//nodeType = 3是文本节点 nodeType = 1是html节点
return lipre;
}
catch (ex) { return null; }
}
/*------------------------------------------------------------
兼容FF的nextSibling
------------------------------------------------------------*/
function nextElementSlibing(linext) {
try {
do {
linext = linext.nextSibling;
if (!linext) return null;
} while (linext.nodeType != 1)//nodeType = 3是文本节点 nodeType = 1是html节点
return linext;
}
catch (ex) { return null; }
}