使用JavaScript更改内联CSS

Eat*_*ode 0 html javascript css

我一直在尝试单击图像时更改此div标签的样式,并且该样式不起作用。首先,我想检查一下样式是否为“ display:none;”。或“ display:block”。但是,当我尝试警告该值时,无论是在显示设置为无时还是在设置为阻止时,它都返回“ undefined”。

<div id="navbar-mobile-id" style="display:block;" class="navbar-mobile">
Run Code Online (Sandbox Code Playgroud)

这在我的函数中:(函数在单击时起作用,但会提示“未定义”)

alert(console.log(document.getElementById("navbar-mobile-id").style.display));
Run Code Online (Sandbox Code Playgroud)

这应该提醒“阻止”或“无”

Que*_*tin 7

返回值console.log()就是undefined

如果你想提醒的价值display属性,那么你必须要警惕的是

alert(document.getElementById("navbar-mobile-id").style.display);
Run Code Online (Sandbox Code Playgroud)