gpt4 book ai didi

javascript - Electron:.setAttribute 不起作用(不同)

转载 作者:行者123 更新时间:2023-12-03 04:16:33 24 4
gpt4 key购买 nike

我尝试在以下内容上使用 .setAttribute:

   <div class="media-body">
<small>Total MA'ers found</small>
<h2 id="totalma" class="media-heading animate-number" data-value="29" data-animation-duration="1500">0</h2>
</div>

与:

document.getElementById('totalma').setAttribute("data-value", 90);

当我在浏览器中的 .htm 文件上尝试此操作时,它工作正常。然而,对于 Electron 来说却并非如此。该值没有更改为 90。问题可能是什么?

两个代码都存储在 home.htm 中

最佳答案

The name of a custom data attribute in Javascript is the name of the same HTML attribute but in camelCase and with no dashes, dots, etc.

所以在你的情况下这会起作用

document.getElementById('totalma').setAttribute("dataValue", 90);

您可以在此处找到有关自定义 data-* 属性的更多信息:- https://developer.mozilla.org/en/docs/Web/API/HTMLElement/dataset

关于javascript - Electron:.setAttribute 不起作用(不同),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44115789/

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