Javascript崩溃延迟功能

时间:2016-10-17 06:38:16

标签: javascript jquery html css twitter-bootstrap

我希望在按下按钮时实现用另一个替换旧折叠内容的功能。当我尝试使用引导按钮data-toggledata-taget属性并使用javascript时,我得到延迟隐藏和显示功能。

我的示例代码:

<table class="table"><thead class="thead-inverse"><tr><th>Column1</th><th>Column2</th></tr></thead>

<tr><td><button type="button" class="btn btn-danger text-center" data-toggle="collapse" href="#contentID" id="errorButton"></span>SwapContent</button></td><td><button type="button" class="btn btn-info" data-toggle="collapse" data-target=".contentClass" id="noteButton">SwapContent2</button></td></tr>

<script type="text/javascript">
  $('#errorButton').on('click', function(event) {
    $("#contentID.collapse.danger").collapse("show");
    $(".collapse.info.contentClass, .collapse.warning.contentClass").collapse("hide");
  });
    $('#noteButton').on('click', function(event) {
    $("#contentID.collapse.danger").collapse("hide");
    $(".collapse.info.contentClass, .collapse.warning.contentClass").collapse("show");
  });
</script>

<tr class="collapse info contentClass"><td colspan="2" style="padding: 0px; padding-left: 5px">InfoTest&emsp;&emsp;InfoContent</td></tr>
<tr class="collapse info contentClass"><td colspan="2" style="padding: 0px; padding-left: 5px">InfoTest&emsp;&emsp;InfoContent</td></tr>
<tr class="collapse warning contentClass"><td colspan="2" style="padding: 0px; padding-left: 5px">Test&emsp;&emsp;Content</td></tr>
<tr class="collapse warning contentClass"><td colspan="2" style="padding: 0px; padding-left: 5px">Test&emsp;&emsp;Content</td></tr>
<tr class="collapse warning contentClass"><td colspan="2" style="padding: 0px; padding-left: 5px">Test&emsp;&emsp;Content</td></tr>
<tr class="collapse warning contentClass"><td colspan="2" style="padding: 0px; padding-left: 5px">Test&emsp;&emsp;Content</td></tr>
<tr class="collapse warning contentClass"><td colspan="2" style="padding: 0px; padding-left: 5px">Test&emsp;&emsp;Content</td></tr>
<tr class="collapse info contentClass"><td colspan="2" style="padding: 0px; padding-left: 5px">InfoTest&emsp;&emsp;InfoContent</td></tr>
<tr class="collapse info contentClass"><td colspan="2" style="padding: 0px; padding-left: 5px">InfoTest&emsp;&emsp;InfoContent</td></tr>

<tr id="contentID" class="collapse danger"><td colspan="2"><table class ="table"><thead class="thead-default"><tr><th>Column1</th><th>Column2</th></tr></thead>
<tr><td>Column1Content</td><td>Column2Content</tr>

</table>

Bootply执行相同的代码:http://www.bootply.com/fv4WsHXXlm以显示在按钮之间按下旧内容在隐藏之前停留在屏幕上一段时间,我希望它同时发生。

1 个答案:

答案 0 :(得分:1)

已经找到了解决方案。诀窍是使用jQuery hide()show()而不是collapse("hide")collapse("show")