This article describes the method of custom functions to implement IE7 and IE8 incompatible with trim functions in js. Share it 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="check" onclick="check();"/> </center> </body> </html>This solves the problem that js does not support trim on IE.
I hope this article will be helpful to everyone's JavaScript programming.