使用Bootstrap单击“我同意”后如何使栏消失

时间:2018-11-19 16:19:49

标签: javascript html html5 bootstrap-4 bootstrap-modal

enter image description here,有人知道单击“我同意”后如何使该栏消失吗?我一直在寻找引导程序,但找不到解决方案。请帮忙。下面是我的代码:

<div id="cookie-message" class="cookie-message notification center-horizontal bottom static enable"> 
            <div class="strip color-ash" >
              <span class="show-tablet">We use cookies to deliver our services.</span>
              By using our website, you agree to the use of cookies as described in our&nbsp;
              <a class="color-oil" href="/assets/static/downloads/privacy-policy.pdf" target="_blank">Privacy&nbsp;Policy</a>&nbsp;—&nbsp; &nbsp;<a tabindex="0" href="#" class="cm-close color-deepblue">I&nbsp;Agree</a>
            </div>
          </div>

2 个答案:

答案 0 :(得分:0)

由于您使用的是Bootstrap,请尝试使用jQuery:

MainModule
  1. 您要将点击事件监听器添加到链接中
  2. 发生单击时,我们得到div并调用hide方法。

让我知道它是否对您有用。

答案 1 :(得分:0)

具有核心响应类.cm-close.color-deepblue的目标链接;向其添加事件侦听器;然后点击parentNode(div id =“ cookie-message”)不显示任何内容。

<div id="cookie-message" class="cookie-message notification center-horizontal bottom static enable">
  <div class="strip color-ash">
    <span class="show-tablet">We use cookies to deliver our services.</span> By using our website, you agree to the use of cookies as described in our&nbsp;
    <a class="color-oil" href="/assets/static/downloads/privacy-policy.pdf" target="_blank">Privacy&nbsp;Policy</a>&nbsp;—&nbsp; &nbsp;<a tabindex="0" href="#" class="cm-close color-deepblue">I&nbsp;Agree</a>
  </div>
</div>
<script>
  document.querySelector('.cm-close.color-deepblue').addEventListener('click', (event) => event.target.parentNode.style = "display:none")
</script>

带有bar的简化版本为:

<div id="bar">

  <div id="cookie-message">
    <div>
      By using our website, you agree to the use of cookies as described in our&nbsp;
      <a href="#">Privacy&nbsp;Policy</a>&nbsp;—&nbsp; &nbsp;<a href="#" class="link">I&nbsp;Agree</a>
    </div>
  </div>

</div>
<script>
  document.querySelector('.link').addEventListener('click', () => document.querySelector('#bar').style = "display:none")
</script>