手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >jquery trim() 功能源代码
jquery trim() 功能源代码
摘要:复制代码代码如下://UsedfortrimmingwhitespacetrimLeft=/^s+/,trimRight=/s+$/,//U...

复制代码 代码如下:

// 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 trim() 功能源代码】相关文章:

jquery预加载图片的方法

Javascript随机显示图片的源代码

鼠标图片振动代码

jquery滚动特效集锦

jquery使用经验小结

用javascript动态注释掉HTML代码

将HTML自动转为JS代码

AngularJS 最常用的功能汇总

jQuery预加载图片常用方法

jquery 构造函数在表单提交过程中修改数据

精品推荐
分类导航