复制代码 代码如下:// 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是匹配右边的空格
推荐阅读
获取css样式表内样式的js函数currentStyle(IE),defaultView(FF)
可是DOM.style这种写法只能访问<DOM style=""></DOM>,这样在标签里内置的样式,如果样式写在<style type="text/css"></style>,或者.css文件里,那么就办法读到样式了。 其实呢,还有别的方法可以读到这些样式信息>>>详细阅读
本文标题:jquery trim() 功能源代码
地址:http://www.17bianji.com/kaifa2/JS/24910.html
1/2 1