javascript中去除左右空格
RT:求在javascript中去除左右空格的写法
if(leftTrim(rightTrim(document.getElementById( "TextBox1 ").value)) == " ")
{
alert( '暗暗啊 ');
}
提示缺少对象
------解决方案--------------------//函数
String.prototype.trim = function(){return this.replace(/(^\s*)|(\s*$)/g, " ");}
String.prototype.ltrim = function(){return this.replace(/^\s*/, " ");}
String.prototype.rtrim = function(){return this.replace(/\s*$/, " ");}
使用
" abc ".trim();
" abc ".ltrim();
"abc ".rtrim();