首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

惯用的js函数处理

2012-10-25 
常用的js函数处理/** * Return a string with &, and replaced with their entities */ function esca

常用的js函数处理
/**
* Return a string with &, < and > replaced with their entities
*/
function escapeHtml(original) {
  return original.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;').replace(/'/g,'&#039;');
};

/**
* Replace common XML entities with characters
*/
function unescapeHtml(original) {
  return original.replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&quot;/g,'"').replace(/&#039;/g,"'").replace(/&amp;/g,'&');
};
/*
* Trim() function
*/
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, "");
}

热点排行
Bad Request.