gpt4 book ai didi

javascript - 针对 JSON 数据属性的 jQuery 选择器

转载 作者:行者123 更新时间:2023-11-30 16:26:10 24 4
gpt4 key购买 nike

如果数据以 JSON 格式存储,是否可以使用 jQuery 选择器来定位 HTML5 数据属性的值?

例如,如果我有类似 <button data-id="5">Some action</button> 的东西, 我可以使用 $("button[data-id='5']")选择该按钮。

但是,我的数据存储为 <button data-properties='{"id":5,"name":"foo"}'>Some action</button> .有没有我可以使用的选择器,或者我必须使用 .filter()例如?

最佳答案

$("button[data-properties*='\"id\":5']")

我现在能想到的最接近的是这个

*= 翻译成“属性包含选择器”

\是从 "中删除特殊含义并改为考虑它们

关于javascript - 针对 JSON 数据属性的 jQuery 选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34116413/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com