常用的js函数处理

/**

*Returnastringwith&,<and>replacedwiththeirentities

*/

functionescapeHtml(original){

returnoriginal.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;').replace(/'/g,'&#039;');

};

/**

*ReplacecommonXMLentitieswithcharacters

*/

functionunescapeHtml(original){

returnoriginal.replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&quot;/g,'"').replace(/&#039;/g,"'").replace(/&amp;/g,'&');

};

/*

*Trim()function

*/

String.prototype.Trim=function(){

returnthis.replace(/(^\s*)|(\s*$)/g,"");

}

String.prototype.LTrim=function(){

returnthis.replace(/(^\s*)/g,"");

}

String.prototype.RTrim=function(){

returnthis.replace(/(\s*$)/g,"");

}

相关推荐