第一种:
|
String.prototype.lTrim = function() { return this.replace(/^\s*/,""); };//去掉左面空格; String.prototype.rTrim = function() { return this.replace(/\s*$/,""); };//去掉右面空格; String.prototype.Trim = function() { return this.lTrim().rTrim(); };//记得各句后都有分号 |
第二种:
str = str.slice(1); str.lTrim(); } return str; }
function rTrim(str) { if(str.charAt(str.length-1)=="") { str = str.slice(0,str.length-1); str.rTrim(); } return str; }
function trim(str){ return rTrim(ltrim(str));
function lTrim(str) { if(str.charAt(0)=="") {
|
31}以上代码供初学者学习。是javascript脚本中最基础的函数
,自我感觉第一种比较好,采用原型方式。望各位发表高见

【责编:michael】