gpt4 book ai didi

javascript - 使用 JavaScript 设置元素数据图标

转载 作者:太空狗 更新时间:2023-10-29 15:46:12 24 4
gpt4 key购买 nike

我的 HTML 中有以下按钮元素

<button id="play-pause" aria-hidden="true"></button>

在 jQuery 就绪事件中,我运行以下代码:

$('#play-pause').attr('data-icon', '&#xe00a;')

把 HTML 元素变成这个

<button id="play-pause" aria-hidden="true" data-icon="&#xe00a;"></button>

在浏览器(Chrome 稳定版)中呈现如下:

play pause button

但是,如果我删除 JavaScript 代码,手动将 HTML 更改为以下内容(这与 JS 所做的相同)并刷新页面:

<button id="play-pause" aria-hidden="true" data-icon="&#xe00a;"></button>

然后它呈现如下:

play pause button rendered properly

有什么区别?

我怀疑这无关紧要,但这是 CSS:

/* Use the following CSS code if you want to use data attributes for inserting your icons */
[data-icon]:before {
font-family: '45sound';
content: attr(data-icon);
speak: none;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
font-style:normal;
}

最佳答案

使用 Unicode 值:

$('#play-pause').attr('data-icon', '\uE00A');

关于javascript - 使用 JavaScript 设置元素数据图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16680948/

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