js去除左右两边空格,提取自jquery trim函数,绝对好用
[javascript]
strim = String.prototype.trim;
rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g
trim = strim && !strim.call("\uFEFF\xA0") ?
function( text ) {
return text == null ?
"" :
strim.call( text );
} :
function( text ) {
return text == null ?
"" :
( text + "" ).replace( rtrim, "" );
}
使用方法
[javascript]
var str = " abc ";
var newStr = str.trim();
补充:web前端 , JavaScript ,