我正在WordPress插件中克隆或可重复的手风琴。但是问题是,当我克隆div元素部分时,它不起作用。它被冻结。如何使其工作? 克隆HTML部分:
<div class="panel panel-default template">
<div class="panel-heading"> <span class="glyphicon glyphicon-remove-circle pull-right ">Remove</span>
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseThree">
Collapsible Group Item #2 (template panel)
</a>
</h4>
</div>
<div id="collapseThree" class="panel-collapse collapse">
<div class="panel-body">Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch.</div>
<?php
$settings = array(
'teeny' => true,
'textarea_rows' => 15,
'tabindex' => 1
);
wp_editor(esc_html( __(get_option('whatever_you_need', 'whatever'))), 'terms_wp_content', $settings);
?>
</div>
</div>
JavaScript部分:
$(document).ready(function(){
var $template = $(".template");
var hash = 0;
$(".btn-add-panel").on("click", function () {
var $newPanel = $template.clone();
$newPanel.find(".collapse").addClass('in');
$newPanel.find(".accordion-toggle").attr("href", "#" + (++hash))
.text("Dynamic panel #" + hash);
$newPanel.find(".panel-collapse").attr("id", hash);
$("#accordion").append($newPanel.fadeIn());
});
$(document).on('click', '.glyphicon-remove-circle', function () {
$(this).parents('.panel').get(0).remove();
});
});