No hay ningún problema para usar la función de recorte de JavaScript en Firefox
<script language = "javaScript"> var test1 = "aa"; test1 = test1.ToString (); test1 = test1.trim (); </script>
No hay problema para usar esto bajo Firefox, pero se informará en IE.
Entonces podemos modificarlo
String.prototype.trim = function () {return this.replace (/(^/s*) | (/s*$)/g, "");}Agregue esta oración en la cabeza, y lo anterior se puede ejecutar bajo IE y FF.
<script language = "javascript"> string.prototype.trim = function () {return this.replace (/(^/s*) | (/s*$)/g, "");} var test1 = "aa"; test1 = test1.ToString (); test1 = test1.trim (); </script>Métodos proporcionados por jQuery:
<! Doctype html> <html> <head> <script src = "http://code.jquery.com/jquery-latest.js"> </script> </leve> <body> <boton> show trim Ejemplo </botte> <script> $ ("botón"). Haga clic (function () {var str = "muchos de los espacios y después"; alerta ("'' '" = jQuery.trim (str); </script> </body> </html>