IE8及以下不支持trim()的处理方法
IE8以及IE8以下不支持trim()方法,我们需要通过JS的原型,重新定义trim()方法
下面这个方法貌似是可以的,你可以试试:
- String.prototype.trim=function(){
- returnthis.replace(/(^\s*)|(\s*$)/g, “”);
- }
- alert(“22”.trim());
- console.log(“22”.trim());
当然,更好的方法应该是使用jquery自带的trim()方法,$.trim(“ xx “);
转载于//blog.51cto.com/hanchaohan/1176355
还没有评论,来说两句吧...