我一直在尝试在单击图像时更改此 div 标签的样式,但它不起作用。 首先我想检查样式是否为“display:none;”或“显示: block ”。但是,当我尝试警告该值时,当显示设置为无和设置为阻止时,它都会返回“未定义”。
<div id="navbar-mobile-id" style="display:block;" class="navbar-mobile">
这是在我的函数中:(单击时函数起作用但警告“未定义”)
alert(console.log(document.getElementById("navbar-mobile-id").style.display));
这应该提醒“阻止”或“无”
最佳答案
console.log()
的返回值为undefined
如果你想提醒 display
属性的值,那么你必须提醒 that。
alert(document.getElementById("navbar-mobile-id").style.display);
关于javascript - 使用 JavaScript 更改内联 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57593666/