Javascript 去空白的語法

 

<SCRIPT LANGUAGE="JavaScript">
// Trim() , Ltrim() , RTrim()
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.prototype.Trim= function() { return this.lTrim().rTrim(); }                //利用LTrim、RTrim來實做的trim
</SCRIPT>

 

by mhchen15 on 15 11 月, 2013 in Javascript - Tags:
Tags:

There are no comments.

Name*: Website: E-Mail*:
XHTML: You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>