首页 > Web开发 > 详细

IE7/IE8不兼容js trim函数,自己实现

时间:2014-09-24 12:10:28      阅读:296      评论:0      收藏:0      [点我收藏+]
<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>  
这样就解决了IE上js不支持trim的实现

IE7/IE8不兼容js trim函数,自己实现

原文:http://blog.csdn.net/benjamin_whx/article/details/39521551

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!