为什么我得到错误IE修剪方法是't支持

Why do I get the error IE Trim method isn't supported?

本文关键字:支持 方法 修剪 错误 IE 为什么      更新时间:2023-09-26

可能重复:
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——请参阅这个问题的答案中指出的解决方案