【问题标题】:Show nonunique div class on button click jquery在按钮单击jquery上显示非唯一的div类
【发布时间】:2016-05-16 14:49:16
【问题描述】:

我想在按下按钮时显示 .unhideme 的 div 类。此类是动态生成的,因此有多个具有相同类名的 div。使用 JQuery 如何正确显示此块?

<div id="negativeButtons">
 <div class="unhideme" name="unhideme" style="display:none">
  <h3>Comments</h3>
  <textarea name="unhappymanager" id="unhappymanager"></textarea>
 </div>
<input type="submit" class="excused" name="negativexcused" value="Excused">
<input type="button" class="unexcused" name="unexcused" value="Unexcused">
<input type="submit" class="commentpushDB" name="commentpushDB" style="display:none" value="Submit">
</div>

这里我有适用于其他按钮的 jquery,但我似乎找不到可以显示 div 的函数。

$(document).ready(function() {
 $(".unexcused").click(function() {
  $(this).closest(".unhideme").show();
  $(this).closest(".unexcused").hide();
  $(this).prev(".excused").hide();
  $(this).next(".commentpushDB").show();
 });
});

【问题讨论】:

    标签: javascript jquery html


    【解决方案1】:

    您必须使用.siblings() 方法:

    $(".unexcused").click(function() {
      $(this).siblings(".unhideme").show();
      $(this).siblings(".unexcused").hide(); // <---- ?? why hide the buttons.
      $(this).prev(".excused").hide();
      $(this).next(".commentpushDB").show();
    });
    

    这是因为按钮和 div 是兄弟姐妹而不是父母。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-20
      • 2011-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-07
      • 2021-12-03
      • 1970-01-01
      相关资源
      最近更新 更多