gpt4 book ai didi

javascript如何获取html样式的自定义属性值

转载 作者:太空宇宙 更新时间:2023-11-04 12:51:29 25 4
gpt4 key购买 nike

我有一些带有一些内联样式的 html 元素以及自定义 css 属性。现在我可以访问每个样式属性,但不能访问我的自定义样式属性。

这是我的代码。

<img id="myimg" class="ImgClass" style="overfolow:hidden;position:absolute;mycustomProp:100;top:15;left:20">

这里我无法获取 mycustomProp。

有什么帮助吗?

最佳答案

document.getElementById("myimg").getAttribute("style")检索属性。

document.getElementById("myimg").setAttribute("style",<string>)可以用来改变它。

关于javascript如何获取html样式的自定义属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26126392/

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