var xpRes = doc.evaluate(sExpr, this, nsRes2, 9, null);
return xpRes.singleNodeValue;
};
Node.prototype.transformNode = function(oXsltNode)
{
var doc = this.nodeType==9 ? this : this.ownerDocument;
var processor = new XSLTProcessor();
processor.importStylesheet(oXsltNode);
var df = processor.transformToFragment(this, doc);
return df.xml;
};
Node.prototype.transformNodeToObject = function(oXsltNode, oOutputDocument)
{
var doc = this.nodeType==9 ? this : this.ownerDocument;
var outDoc = oOutputDocument.nodeType==9 ? oOutputDocument : oOutputDocument.ownerDocument;
var processor=new XSLTProcessor();
processor.importStylesheet(oXsltNode);
var df=processor.transformToFragment(this,doc);
while (oOutputDocument.hasChildNodes())
{
oOutputDocument.removeChild(oOutputDocument.lastChild);
}
/* */
if (!Array.prototype.forEach)
{
Array.prototype.forEach = function(f, obj)
{
var l = this.length;
for (var i = 0; i < l; i++)
{
f.call(obj, this[i], i, this);
}
};
}
/* */
if (!Array.prototype.filter)
{
Array.prototype.filter = function(f, obj)
{
var l = this.length;
var res = [];
for (var i = 0; i < l; i++)
{
if (f.call(obj, this[i], i, this))
{
res.push(this[i]);
}
}
return res;
};
}
/* */
if (!Array.prototype.map)
{
Array.prototype.map = function(f, obj)
{
var l = this.length;
var res = [];
for (var i = 0; i < l; i++)
{
res.push(f.call(obj, this[i], i, this));
}
return res;
};
}
/* */
if (!Array.prototype.some)
{
Array.prototype.some = function(f, obj)
{
var l = this.length;
for (var i = 0; i < l; i++)
{
if (f.call(obj, this[i], i, this))
{
return true;
}
}
return false;
};
}
/* */
if (!Array.prototype.every)
{
Array.prototype.every = function(f, obj)
{
var l = this.length;
for (var i = 0; i < l; i++)
{
if (!f.call(obj, this[i], i, this))
{
return false;
}
}
return true;
};
}
/******************************************************************************
* Date
******************************************************************************/
if (/(y+)/.test(format))
{
format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
}
for (var k in o)
{
if (new RegExp("("+ k +")").test(format))
{
format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] :
("00"+ o[k]).substr((""+ o[k]).length));
}
}
/******************************************************************************
* Math
******************************************************************************/
/******************************************************************************
* Number
******************************************************************************/
还有就是不要在正则里动不动就添加 g 模式:
/^([\u4E00-\u9FA5])*$/g //String.prototype.isAllChinese
这句正则里的 g 模式若是配合以 m 模式那还说得过去,你即然没有 m 那何必要添个 g ?
还有你用的是 * 若这一个空字符串你也认为是 isAllChinese ?所以应该用+
/^[\u4e00-\u9fa5\uf900-\ufa2d]+$/
var pattern = /[\u4E00-\u9FA5]/g; //String.prototype.isContainChinese
这句正则里加了一个无用的 g ,对系统消耗则相差甚大呀