您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

jquery trim() 功能源代码_jquery

2025/4/22 7:05:21发布27次查看
复制代码 代码如下:
// 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是匹配右边的空格
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product