javascript 裡要削去字串空白可以使用trim,ltrim,rtrim
在IE上使用javascript的function trim()會發生錯誤,可以加上此段讓IE正常
if(typeof String.prototype.trim !== 'function') {
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g,"");
}
}
if(typeof String.prototype.ltrim !== 'function') {
String.prototype.ltrim = function() {
return this.replace(/^\s+/,"");
}
}
if(typeof String.prototype.rtrim !== 'function') {
String.prototype.rtrim = function() {
return this.replace(/\s+$/,"");
}
}
文章標籤
全站熱搜
