js 去除左右首尾空格

ie6不支持jquery的trim()方法,于是找来这个代码备用

>>> "sss".replace(/^\s+|\s+$/g, "")
"sss"

>>> " sss".replace(/^\s+|\s+$/g, "")
"sss"

>>> " sss ".replace(/^\s+|\s+$/g, "")
"sss"

>>> " s s s ".replace(/^\s+|\s+$/g, "")
"s s s"

你可能感兴趣的:(JavaScript,jquery,IE)