码迷,mamicode.com
首页 > 其他好文 > 详细

ie7/8浏览器报错:对象不支持“trim”属性或方法

时间:2014-06-28 20:33:06      阅读:294      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   使用   strong   cti   

解决方法:

方法1:

使用jquery里面的全局函数$.trim()代替原生js方法trim():

$.trim( 你要替换的字符 );

方法2:


Function.prototype.method = function (name, func) {
    this.prototype[name] = func;
    return this;
};
if (!String.prototype.trim) { //判断下浏览器是否自带有trim()方法
    String.method(‘trim‘, function () {
        return this.replace(/^\s+|\s+$/g, ‘‘);
    });
    String.method(‘ltrim‘, function () {
        return this.replace(/^\s+/g, ‘‘);
    });
    String.method(‘rtrim‘, function () {
        return this.replace(/\s+$/g, ‘‘);
    });
}

 

使用方法2,这样就可以直接在你的js里面 原生调用 .trim()  方法了

ie7/8浏览器报错:对象不支持“trim”属性或方法,布布扣,bubuko.com

ie7/8浏览器报错:对象不支持“trim”属性或方法

标签:style   blog   color   使用   strong   cti   

原文地址:http://www.cnblogs.com/joeylee/p/3794775.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!