源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

jquery trim() 功能源代码

  • 时间:2020-04-20 09:03 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:jquery trim() 功能源代码
[u]复制代码[/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是匹配右边的空格
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部