Javascript 如何在追加的div中追加div?

Javascript 如何在追加的div中追加div?,javascript,jquery,wordpress,Javascript,Jquery,Wordpress,我试图将一个退出的div附加到另一个追加到页面中的div 到目前为止,我已经这样做了,但它错过了时机,或者可能是逻辑不正确 $(".signature-container").append( $('#signature-pad')); 以下是我在常规WordPress页面上使用的html: <div id="signature-pad" class="signature-pad"> <div class="signature-pad--body"> <ca

我试图将一个退出的div附加到另一个追加到页面中的div

到目前为止,我已经这样做了,但它错过了时机,或者可能是逻辑不正确

$(".signature-container").append( $('#signature-pad'));  
以下是我在常规WordPress页面上使用的html:

<div id="signature-pad" class="signature-pad">
<div class="signature-pad--body">
  <canvas width="664" height="235" style="touch-action: none;"></canvas>
</div>
<div class="signature-pad--footer">
  <div class="description">Sign above</div>

  <div class="signature-pad--actions">
    <div>
      <button type="button" class="button clear" data-action="clear">Clear</button>
      <button type="button" class="button" data-action="change-color">Change color</button>
      <button type="button" class="button" data-action="undo">Undo</button>

    </div>
    <div>
      <button type="button" class="button save" data-action="save-png">Save as PNG</button>
      <button type="button" class="button save" data-action="save-jpg">Save as JPG</button>
      <button type="button" class="button save" data-action="save-svg">Save as SVG</button>
    </div>
  </div>
</div>

上面的标志
清楚的
变色
撤消
另存为PNG
另存为JPG
另存为SVG

签名容器是附加到该页面的忍者表单。

请尝试以下方法:

$(document).find(".signature-container").append( $('#signature-pad').clone());  
试着这样做:

$(document).find(".signature-container").append( $('#signature-pad').clone());  

给你一个解决方案

$(".signature-container").append($('#signature-pad').clone());
.clone()
方法将克隆
#签名板
容器及其内容

下面是示例解决方案

$(“.signature container”).append($(“#signature pad”).clone()
#签名板{
边框:1px实心#000;
}
.签名容器{
填充:10px;
边框:1px实心#00f;
}

测试1


给你一个解决方案

$(".signature-container").append($('#signature-pad').clone());
.clone()
方法将克隆
#签名板
容器及其内容

下面是示例解决方案

$(“.signature container”).append($(“#signature pad”).clone()
#签名板{
边框:1px实心#000;
}
.签名容器{
填充:10px;
边框:1px实心#00f;
}

测试1


签名板
是现有的div吗?是的,它是现有的div。
签名板
是现有的div吗?是的,它是现有的div。@user3821656,现在检查。我做了两个更改。@user3821656,现在检查。我做了两个更改。@user3821656有错误吗,伙计?如果您也共享
HTML
,那就太好了。@user3821656有错误吗?如果您也共享
HTML
,那就太好了。
.signature container
以前是如何附加到页面的?请尝试此
$(.signature container”).append($(“#signature pad').clone().HTML())它在wordpress中,签名板只是页面上的html。然后签名容器是一个附加在页面上的忍者表单。在执行上述jQuery附加代码时,需要确保
.signature container
是否存在。还要确保
.signature container
不在iframe中。
#签名板
也是如此。它们都不是iframe。我可以将签名板附加到签名容器之外的任何东西中。因为页面加载时它不存在。我想它是在页面加载后的某个时候被WordPress追加的。签名容器存在后,我需要追加它。
.signature container
以前是如何追加到页面的?请尝试此
$(.signature container”).append($('#signature pad').clone().html()它在wordpress中,签名板只是页面上的html。然后签名容器是一个附加在页面上的忍者表单。在执行上述jQuery附加代码时,需要确保
.signature container
是否存在。还要确保
.signature container
不在iframe中。
#签名板
也是如此。它们都不是iframe。我可以将签名板附加到签名容器之外的任何东西中。因为页面加载时它不存在。我想它是在页面加载后的某个时候被WordPress追加的。我需要在签名容器存在后附加它。