您的位置:首页 > Web前端 > JQuery

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

2012-09-29 12:57 211 查看
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'
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: