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

js去空格技巧分別去字符串前后、左右空格

 更新時(shí)間:2013年10月21日 17:03:22   作者:  
js去空格想必大家多少都會(huì)點(diǎn)吧,在接下來的文章中為大家詳細(xì)介紹下如何分別去字符串前后,左邊,右邊空格,感興趣的朋友可以參考下
分別去字符串前后,左邊,右邊空格
復(fù)制代碼 代碼如下:

String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g,"")}
String.prototype.ltrim = function(){ return this.replace(/^\s+/g,"")}
String.prototype.rtrim = function(){ return this.replace(/\s+$/g,"")}

為String對(duì)象增加一個(gè)trim方法。
以后就可以這樣使用:
復(fù)制代碼 代碼如下:

var s = " abc ";
s = s.trim(); // s是個(gè)String,可以使用剛定義的trim方法。
alert(s);

相關(guān)文章

最新評(píng)論