调用方法就是: var str = " 12345 "; alert(str.Trim()); alert(str.LTrim()); alert(str.RTrim())
javascript 本身的身体日过你类型就有trim方法的啊
String.prototype.trim = function() { return this.replace(/(^[\\s]*)|([\\s]*$)/g, ""); } var s = " This is a String "; s = s.trim(); // s = "This is a String"
晕..用trim啊 为什么不用呢>.<
var sB=" 1 23 "; var sA=sB.replace(/(^\s*)|(\s*$)/g,""); 去掉前后空格
{
return this.replace(/(^[\\s]*)|([\\s]*$)/g, "");
}就这么简单
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, "");
}如还不懂 继续跟帖!
var str = " 12345 ";
alert(str.Trim());
alert(str.LTrim());
alert(str.RTrim())
{
return this.replace(/(^[\\s]*)|([\\s]*$)/g, "");
}
var s = " This is a String ";
s = s.trim(); // s = "This is a String"
var sA=sB.replace(/(^\s*)|(\s*$)/g,"");
去掉前后空格