用途
jQuery.trim()函数用于删除指定字符串开头和结尾的空格。
$.trim()函数将删除指定字符串开头和结尾的所有的换行符、空格,以及制表符。
语法
jQuery.trim(str)
参数
str:要去除前后空格的字符串
返回值
jQuery.trim()方法返回去除了前后空格的字符串
示例说明
var str = " ???hello, how are you? ??";console.log($.trim(str)); ???// "hello, how are you?"str = " ???\r\n\thello, how are you?\r\n\t ???";console.log($.trim(str)); // "hello, how are you?"
$.trim(undefined); ??// 返回"",而不报错,js原生trim()会报错$.trim(null); ?// 返回"",而不报错,js原生trim()会报错
jQuery.trim()
原文地址:http://www.cnblogs.com/zwwhnly/p/7494266.html