2016-06-21 27 views
0

我有以下的div块JQuery的show()方法亘古不按预期工作

 <div class="score-description col-sm-3"> 
      <table class="table table-striped"> 
       <thead> 
        <th> Score 
        </th> 
        <th> Description 
        </th> 
       </thead> 
       <tr> 
        <td>0</td> 
        <td>Poor</td> 
         ... 
         ... 
       </tr> 
      </table> 

     </div> 

我想点击下面的按钮时,显示该块。

<Button class="btn btn-warning show-score-description-button"> 
    Score Descriptions 
</Button> 

我有以下脚本来显示块

$(".show-score-description-button").click(function(){ 
     $(".score-description").show(); 
}) 

CSS的.score-描述类

.score-description{ 
     position: fixed; 
     z-index: 1; 
     overflow: scroll; 
     margin-top:-100px; 
     height: 50%; 
     margin-left: 7%; 
     margin-top: 5%; 
     background-color: #ffffff; 
     display: none; 

    } 
    .score-description table th{ 
     border: 2px solid #aaaabb; 
    } 
    .score-description table td{ 
     border: 2px solid #aaaabb; 
    } 

问题是当我单击该块被示出的按钮,并立即隐藏。我在想什么?

回答

6

让您的按钮type="button"。目前您的button正在提交该页面。所以它显示的页面处于默认状态。

<Button type="button" class="btn btn-warning show-score-description-button"> 
Score Descriptions 

+3

的OP的代码工作正常,因为它是,所以这是唯一符合逻辑的答案在这里,+1 –

+0

@RoryMcCrossan是代码精唯一按钮创建问题 – Mairaj

1

尝试toggle()

$(".show-score-description-button").click(function() { 
    $(".score-description").toggle(); 
})