欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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)文章

最新評論