'trim()' javascript function issues with Internet Explorer - Stack Overflow

trim() is not working in Internet Explorer(it's working properly in Chrome and Firefox). However I

trim() is not working in Internet Explorer(it's working properly in Chrome and Firefox). However I need to trim the value to prevent empty spaces.

trim() is not working in Internet Explorer(it's working properly in Chrome and Firefox). However I need to trim the value to prevent empty spaces.

Share Improve this question edited Apr 24, 2012 at 10:45 user 87.1k18 gold badges199 silver badges190 bronze badges asked Apr 29, 2011 at 6:05 VissuVissu 2,0439 gold badges42 silver badges59 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

I don't think JavaScript provides trim() does it? Some browsers may implement it, and various libraries implement it.

You can add your own, something like this:

String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
}

If this turns out to be an IE bug, you can always implement your own workaround using RegEx in JavaScript like this left trim function sample - the sample can be expanded to trim both left and right sides. This Regex should work in all browsers.

Have a look @ this -> Trim not working in IE

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745261652a4619237.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信