jQuery.trim() 去除字符两端空格

jQuery.trim( str )     

//返回字符串;

//从字符串的头部和尾部移除空格。

//从字符串的头部和尾部移除空格、换行符、制表符。字符串“中部(中间)”的空格、换行符、制表符是不移出的。

//jquery的换行符是 \n

例子:

$("button").click(function () {
var str = "     lots of spaces before and after\n";
alert("'" + str + "'");

//返回的是'     lots of spaces before and after

'
str = jQuery.trim(str);
alert("'" + str + "' - no longer");
});
//返回的是'lots of spaces before and after'

原文地址:https://www.cnblogs.com/chenjianhong/p/4144933.html