可能重复:
JavaScript中的.trim()在IE 中不起作用
我有下面的代码,但在IE中它说trim方法不受支持。
for (var i = 0; i < here.length; i++) {
if ($(here[i]).html().trim() == "")
$(here[i]).parent().find('#content').css('width', '656px'),
$(here[i]).parent().find('#content p').css('width', '430px');
if ($(another[i]).html() != null) {
if ($(another[i]).html().trim() == "")
$(another[i]).parent().parent().css('display', 'none'),
$('#sidemenu .heading').css('background', 'none');
}
}
我该如何修复它?
较旧版本的浏览器(例如,版本9之前的IE)在其Javascript中没有实现字符串的trim
方法。您有以下选项:
- 改为使用
JQuery.trim
- 或者自己定义trim——请参阅这个问题的答案中指出的解决方案