【问题标题】:Queryselector back slash x2d can't select 'xxx\x2dxxx'Queryselector 反斜杠 x2d 无法选择 'xxx\x2dxxx'
【发布时间】:2021-12-15 08:43:36
【问题描述】:

例如

<table lsdata="{1:'Ship\x2dTo\x20Location',4:true}">
</table>

它不能使用包含选择器document.querySelector("table[lsdata*='Ship\x2d']")的字符串来选择像图像一样的DOM:

我阅读了以下页面但没有答案

【问题讨论】:

    标签: javascript html regex


    【解决方案1】:

    你必须逃避 \ 但在这种情况下 \\ 似乎不起作用所以我尝试使用 \\\\ 并且它起作用了:

    const item = document.querySelector('table[lsdata*="Ship\\\\x2d"]')
    console.log(item)
    <table lsdata="{1:'Ship\x2dTo\x20Location',4:true}">
    </table>

    【讨论】:

    • 太棒了!我没有搜索有关此的文档?
    猜你喜欢
    • 2019-11-12
    • 1970-01-01
    • 1970-01-01
    • 2020-04-11
    • 1970-01-01
    • 1970-01-01
    • 2010-12-14
    • 2013-11-14
    相关资源
    最近更新 更多