我们有时候会按需求在前端用trim()方法将html中的空格去掉,如下面代码:
$("#info-2").html().trim()
但IE6下对trim()方法不能识别 ,解决办法是只要在代码前面加上这段话就好了(去掉注释),如下:
<!-- 要加的话 START -->
//ie6不认识trim方法
if(typeof String.prototype.trim !== 'function') {
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, '');
}
}
<!-- 要加的话 END -->
$("#info-2").html().trim()