jquery trim() 功能源代碼
更新時(shí)間:2011年02月14日 18:45:23 作者:
jquery trim() 作用是,刪除字符串兩邊出現(xiàn)的空格
復(fù)制代碼 代碼如下:
// 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() 作用是,刪除字符串兩邊出現(xiàn)的空格;
其中的關(guān)鍵實(shí)現(xiàn)是text.toString().replace( trimLeft, "" ).replace( trimRight, "" );
是將傳入的字符串分別兩次調(diào)用replace,其中正則表達(dá)trimLeft是匹配左邊的空格,trimRight是匹配右邊的空格
相關(guān)文章
jQuery 隱藏/顯示效果函數(shù)用法實(shí)例分析
這篇文章主要介紹了jQuery 隱藏/顯示效果函數(shù),結(jié)合實(shí)例形式分析了hide()、show()及toggle()函數(shù)的基本功能與使用技巧,需要的朋友可以參考下2020-05-05詳解jQuery獲取特殊屬性的值以及設(shè)置內(nèi)容
在本篇內(nèi)容里小編給大家分享了jQuery獲取特殊屬性的值以及設(shè)置內(nèi)容相關(guān)知識點(diǎn),有需要的朋友們參考下。2018-11-113Z版基于jquery的圖片復(fù)選框(asp.net+jquery)
最近在做一個彩票縮水工具,找了幾個圖片復(fù)選框插件始終感覺不太滿意,自己動手山寨了一下imageTick插件.2010-04-04