通过eventListener打开/关闭传单图例

在导航栏中单击“传奇”时,我试图进行开/关切换。但是,当我为addEventListener构造函数时,我不断收到类型错误。我了解这是因为未定义info,但是我不确定如何定义它,因此可以将style display更改为block,当{{1 }}在导航栏中单击。

有什么建议可以指出正确的方向吗?

HTML:

Legend

CSS:

<!--Navbar-->
    <nav class="navbar">
        <div class="logo">
            <h4> Earthquake Feed</h4>
        </div>
        <ul class="nav-links">
            <li><a href="#simpleModal" id="aboutModal">About</a></li>
            <li><a href="#legend" id="legend">Legend</a></li>
        </ul>
    </nav>

Javascript:

/*CSS for legend*/
.info {
  padding: 6px 8px;
  font: 14px/16px Arial,Helvetica,sans-serif;
  background: white;
  background: rgba(255,255,0.8);
  box-shadow: 0 0 15px rgba(0,0.2);
  border-radius: 5px;
  display: none;
  }

.legend {
  background-color: “black”;
  line-height: 26px;
  color: #555;
  width: auto;
jeseca8897 回答:通过eventListener打开/关闭传单图例

您需要一个DOM元素,该元素指定要设置样式的元素。

function openLegend(){
    document.getElementByClass("legend").style.display = 'block';
}

应该为您工作。

本文链接:https://www.f2er.com/3018104.html

大家都在问