jQuery hide() 效果不佳

标签 jquery html css

<分区>

亲爱的,

一段时间以来,我一直面临以下问题。请帮帮我!

这是我的代码:

HTML

<html>

<head>
  <meta charset="utf-8" />


  <!--css stylesheet-->
  <link href="style.css" rel="stylesheet" />

  <!--jQuery external javascript - CDN-->
  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
  <link href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" rel="stylesheet" />

</head>

<body>

  <div class="header"></div>

  <div class="content"><input type="button" id="sendData" value="send your data" align="center"></div>

  <div class="barChart"><input type="button" id="reenterButton" value="Re-enter">     </div>

</body>

</html>

CSS

.content {
  text-align: center;
  background-color: white;
  width: 650px;
  height: 650px;
  display: inline-block;
  position: relative;
}



.barChart {
  text-align: center;
  background-color: white;
  width: 650px;
  height: 650px;
  display: inline-block;
  position: relative;
  display: none;            // Make .barchart hide initially
}

Javascript

<script type="text/javascript">
$(document).ready(function() {

  $("#sendData").button()                   
                .click(function() {        
                  $("div.content").hide("slide", {direction: "left"}, "slow", function() {
                    $("div.barChart").show("slide", {direction: "right"}, "slow");
                  });
                 }); 

  $("#reenterButton").button()
                 .click(function() {
                  $("div.barchart").hide("slide", {direction: "right"}, "slow", function() {   
                    $("div.content").show("slide", {direction: "right"}, "slow");
                  });
                 });
});
</script>

#sendData 按钮工作正常,但点击#reenterButton 不正常 处理第二条语句(带选择器的语句 ("div.barchart"))。

.barchart 在重新输入按钮上应用点击操作后不隐藏。

这种情况是否与我在 css 文件中设置的 div 状态有关?还是别的?

感谢您的帮助!

最佳答案

您在第二次点击绑定(bind)时输入错误,而不是 $("div.barchart") 应该是 $("div.barChart")

Fiddle

关于jQuery hide() 效果不佳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15895167/

相关文章:

jquery - 'one' 和 'live' 的组合用于提交?

javascript - 解析外部 html 时不会触发 Click 事件

PHP foreach 表列

javascript - 输出不会显示(javascript)

css - 为什么我的 CSS 不能在 IE 中运行?

javascript - 检查值是否在下拉列表中并在 Jquery 中禁用它

javascript - 如何将额外的属性添加到 bootstrapTable 中

php - 避免在 div 中换行

ruby-on-rails - 如何在 Rails 3.1 Asset Pipeline 中使用更少的变量

css - 绝对/固定位置 : preventing items scrolling