简体   繁体   English

如何使用jQuery显示/隐藏隐藏的表行(默认情况下)?

[英]How do I show/hide a hidden - by default - table row with jQuery?

I am trying to show/hide a table row that is hidden by default. 我试图显示/隐藏默认情况下隐藏的表行。 Here is an snippet of what I am doing: 这是我在做什么的摘要:

 function showHidePatientSupportedCont(val) { alert(val == '0'); if (val == '0') { $('#pattient_supported_cont').removeAttr('style').show(); } else { $('#pattient_supported_cont').hide(); } } $(document).ready(function() { $(".btn-0, .btn-1").click(function() { showHidePatientSupportedCont($(this).data('val')); }); }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <table> <tr id="patient_supported_cont" style="display: none"> <td> text text text </td> </tr> </table> <button data-val="0" class="btn-0">Click 0</button> <button data-val="1" class="btn-1">Click 1</button> 

But for some reason the row never gets displayed. 但是由于某种原因,该行从未显示过。 I have read this post and I am doing exactly as in the accepted answer. 我已经阅读了这篇文章,并且所做的工作与接受的答案完全相同。 What I am missing here? 我在这里想念的是什么?

PS: Here is a Fiddle for you to play as well PS: 这也是您演奏的小提琴

You have a typo in both of your identifiers: 您的两个标识符都有错别字:

  if (val == '0') {
    $('#pattient_supported_cont').removeAttr('style').show();
  } else {
    $('#pattient_supported_cont').hide();
  }

to: 至:

  if (val == '0') {
    $('#patient_supported_cont').removeAttr('style').show();
  } else {
    $('#patient_supported_cont').hide();
  }

There is an extra 't' in 'patient' =) “患者”中有一个额外的“ t” =)

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

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