The example in this article describes how to use custom functions to implement the trim function in js that is incompatible with IE7 and IE8. Share it with everyone for your reference. The specific implementation method is as follows:
<html> <head> <title>test</title> <script type="text/javascript"> String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); } function check(){ var str = document.getElementById("test").value; alert(str.trim()); } </script> </head> <body> <center> <input id="test" type="text" /> <input id="but" type="button" value="检验" onclick="check();"/> </center> </body> </html>
This solves the problem that js on IE does not support trim.
I hope this article will be helpful to everyone’s JavaScript programming design.