【问题标题】:Show hidden divs in the new clone () div在新的 clone() div 中显示隐藏的 div
【发布时间】:2017-12-06 15:51:04
【问题描述】:

关于如何保持隐藏的 (display:none) div 隐藏但使其显示在新的克隆 div 中的任何建议?

当我取消显示样式但我需要隐藏它时,克隆工作。我已经广泛尝试研究和解决这个问题,但没有运气。 (可能是因为我是初学者)

这是我的代码:

(新克隆的 div)

<div class="showcontent" class="toggle"></div>

(.poster div 包含要克隆的元素)

<div class=poster><img width='<?php 67*2.3 ?>' height='<?= 98*2.3 ?>' src='<?= $movie['image_url'] ?>'> <br>
<div class=title><h1text><?= $movie['title'] ?></h1text>  </div>  <br>
<span class=year>(<?= $movie['year'] ?>)</span> 
<div class=title style="display:none"><h1text><?= $movie['title'] ?></h1text>  </div>  <br> </div>

(脚本)

$(".poster").click(function(){
img = $(this).clone();
$(".showcontent").show().html(img.removeAttr(''));
}); 

【问题讨论】:

    标签: javascript jquery clone


    【解决方案1】:
    $(".poster").click(function(){
      var divNewPoster = $(this).clone();
    
      divNewPoster.find("div").show();
      // or if you want to be more selective:
      divNewPoster.find(".title").show();
    
      $(".showcontent").empty().show().append(divNewPoster);
    }); 
    

    【讨论】:

    • 出于兴趣,你为什么要empty()>show()>append()而不是html()>show()
    • @DBS 我不记得 $().html() 函数使用 jQuery 包装对象作为参数。
    • 我只是在尝试我正在学习的东西,并且在我需要显示一个隐藏的 div 之前,它碰巧有效
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多