gpt4 book ai didi

javascript - 自定义 HTML 属性的浏览器版本底限

转载 作者:行者123 更新时间:2023-11-28 05:05:14 24 4
gpt4 key购买 nike

哪些浏览器(和版本)不支持自定义属性?

我想为我的标签添加一些自定义属性,我想知道哪些浏览器不能正确处理它。

HTML:

<div id="mydiv" mycustomattribute="I've got one.">Test</div>

JavaScript:

alert(document.getElementById("mydiv").getAttribute("mycustomattribute"));

最佳答案

首先,使用 data-* for custom attributes .这将与 HTML5 兼容。其次,all browsers currently support it在使用 getAttribute()

关于javascript - 自定义 HTML 属性的浏览器版本底限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8978569/

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