gpt4 book ai didi

javascript - 检查嵌入标签是否存在 javascript

转载 作者:行者123 更新时间:2023-11-30 10:44:27 25 4
gpt4 key购买 nike

如何检查我的 html 中是否存在嵌入标记。我通过 javascript 创建了这个标签

    soundEmbed = document.createElement("embed");
soundEmbed.setAttribute("src", "notify.wav");
soundEmbed.setAttribute("hidden", true);
soundEmbed.setAttribute("autostart", true);
soundEmbed.setAttribute("loop", false);
document.body.appendChild(soundEmbed);

但由于我使用的是 autorefresh 和 appendChild,每次刷新都会产生额外的声音。

使用 appendChild,我想我有很多嵌入标签。我认为这可能是额外声音的原因。

最佳答案

在 append 之前添加 soundEmbed.id = "__soundEmbed";。然后,将整个事物包围起来:

if( !document.getElementById("__soundEmbed")) {
soundEmbed = ......;
......
}

关于javascript - 检查嵌入标签是否存在 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9231152/

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