Firefox에서 JavaScript의 트림 기능을 사용하는 데 아무런 문제가 없습니다.
<script language = "javaScript"> var test1 = "aa"; test1 = test1.tostring (); test1 = test1.trim (); </스크립트>
Firefox에서 이것을 사용하는 데 아무런 문제가 없지만 IE 에보 고 될 것입니다.
그런 다음 수정할 수 있습니다
string.prototype.trim = function () {return this.replace (/(^/s*) | (/s*$)/g, "");}이 문장을 머리에 추가하면 위의 문장을 IE와 FF 아래에서 실행할 수 있습니다.
<script language = "javaScript"> string.prototype.trim = function () {return this.Replace (/(^/s*) | (/s*$)/g, "");} var test1 = "aa"; test1 = test1.tostring (); test1 = test1.trim (); </스크립트>jQuery가 제공하는 방법 :
<! docType html> <html> <head> <script src = "http://code.jquery.com/jquery-latest.js"> </script> </head> <body> <bustme> 예제 표시 </button> <clatr ( "button"). "" "); str = jquery.trim (str); </script> </body> </html>