当用户处于pwa状态时,我需要隐藏一个元素。我尝试过
manifest.json
"start_url": "/?mode=standalone"
js
const url = new URL(window.location.href);
if(url.searchParams.get('mode')==='standalone') {
document.getElementsByClassName("pwa").style.display="none";
}
html
<p class="pwa">Some text</p>
我在控制台中没有错误。我无法将元素隐藏在pwa中。怎么做?
document.getElementsByClassName("pwa")
返回HTMLCollection
。您应该迭代pwa元素:
Array.from(
document.getElementsByClassName("pwa")
).forEach((e)=>e.style.display='none')
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句