简体   繁体   English

为什么我的jquery重置?

[英]Why does my jquery reset?

I am attempting to make a second dropdown navigation here, all i want it to do is slide down nicely once its been triggered to show and it does slide down. 我正在尝试在此处进行第二次下拉导航,我想要它做的就是一旦触发显示就很好地向下滑动,并且确实向下滑动。 However it disappears just after a second or so, why does it do that?? 但是,它在一秒钟左右后消失了,为什么要这么做呢?

HTML HTML

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <header></header>
  <nav>
    <a href="">Toggle</a>
  </nav>
  <div id="lower_nav">
    This is some text.
  </div>
  <div></div>
  <footer></footer>
</body>
</html>

SASS 上海社会科学院

*
  margin: 0

header
  background-color: tomato
  height: 120px

nav
  background-color: brown
  padding: 20px
  a
    color: white

div
  background-color: f0f0f0

#lower_nav
  background-color: blue
  padding: 20px
  color: white
  display: none

Jquery jQuery的

$(function() {
  $("a").on("click", function() {
    $("#lower_nav").slideDown();
  });
});

I realised that by clicking a link i am reloading a page, therefore my bar is disappearing. 我意识到通过单击链接可以重新加载页面,因此我的栏消失了。 I solved this with jquery's preventDefault function. 我用jQuery的preventDefault函数解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM