Home > Web Front-end > JS Tutorial > body text

Custom function implements the problem of trim function in js that is incompatible between IE7 and IE8_javascript skills

WBOY
Release: 2016-05-16 16:16:09
Original
1038 people have browsed it

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> 
Copy after login

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.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template