jquerytrim()功能源代碼_jquery
來源:懂視網
責編:小采
時間:2020-11-27 20:58:09
jquerytrim()功能源代碼_jquery
jquerytrim()功能源代碼_jquery: 代碼如下:// Used for trimming whitespace trimLeft = /^\s+/, trimRight = /\s+$/, // Use native String.trim function wherever possible trim: trim function( text ) { return text == n
導讀jquerytrim()功能源代碼_jquery: 代碼如下:// Used for trimming whitespace trimLeft = /^\s+/, trimRight = /\s+$/, // Use native String.trim function wherever possible trim: trim function( text ) { return text == n

代碼如下:
// 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是匹配右邊的空格
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
jquerytrim()功能源代碼_jquery
jquerytrim()功能源代碼_jquery: 代碼如下:// Used for trimming whitespace trimLeft = /^\s+/, trimRight = /\s+$/, // Use native String.trim function wherever possible trim: trim function( text ) { return text == n