【问题标题】:Custom attribute selector not working in IE11自定义属性选择器在 IE11 中不起作用
【发布时间】:2021-05-27 00:17:53
【问题描述】:

有谁知道为什么自定义属性选择器在 IE11 中不起作用,或者还有其他选择自定义属性的方法吗? 我在 Chrome 上运行的代码:

$("[aria-label='" + tempSearchString + "']")
        .parent()
        .css({
          "background-color": "#ae924d",
          "color": "white",
          "cursor": "pointer"
});

我也尝试过使用过滤器,但它似乎在 IE 中不起作用:

$("abbr").filter("[aria-label='" + tempSearchString + "']")

【问题讨论】:

  • 我无法使用您提供的代码重现该问题。我做了一个示例like this,它在 IE 11 中运行良好。您是否使用 F12 开发工具检查 IE 11 中的控制台是否有任何错误?您如何获得tempSearchString?我建议您也可以提供相关的html代码并制作a minimal code snippet,它可以重现问题。这样我们就可以进行测试,看看如何提供帮助。

标签: html jquery jquery-selectors internet-explorer-11


【解决方案1】:

问题出在我使用的 React 库中,它创建了这些自定义属性,并将一些“不可见”字符放在自定义属性的开头/结尾。当我比较 tempSearchString 的字符串和我试图捕捉的属性时,它们在书面上看起来是一样的,但 Text Compare 仍然发现了不同之处。我决定不使用这个库并为这个问题编写了自己的代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-04
    • 1970-01-01
    • 2011-11-07
    • 1970-01-01
    • 2019-12-21
    • 2016-01-23
    • 1970-01-01
    • 2017-05-21
    相关资源
    最近更新 更多