jquery trim() 功能源代码
更新时间:2011年02月14日 18:45:23 作者:
jquery trim() 作用是,删除字符串两边出现的空格
复制代码 代码如下:
// Used for trimming whitespace
trimLeft = /^\s+/,
trimRight = /\s+$/,
// Use native String.trim function wherever possible
trim: trim ?
function( text ) {
return text == null ?
"" :
trim.call( text );
} :
// Otherwise use our own trimming functionality
function( text ) {
return text == null ?
"" :
text.toString().replace( trimLeft, "" ).replace( trimRight, "" );
},
分析:jquery trim() 作用是,删除字符串两边出现的空格;
其中的关键实现是text.toString().replace( trimLeft, "" ).replace( trimRight, "" );
是将传入的字符串分别两次调用replace,其中正则表达trimLeft是匹配左边的空格,trimRight是匹配右边的空格
相关文章
jquery操作复选框(checkbox)的12个小技巧总结
本篇文章主要是对jquery操作复选框(checkbox)的12个小技巧进行了总结介绍,需要的朋友可以过来参考下,希望对大家有所帮助2014-02-02
使用jQuery UI的tooltip函数修饰title属性的气泡悬浮框
使用jQuery UI的tooltip()函数,可以使悬浮提示框不再那么千篇一律,以下是完整的代码,感兴趣的朋友可以参考下哈,希望对大家有所帮助2013-06-06


最新评论