如果"下拉"在一个隐藏的div中,然后放在一个可见的div中,这个" Dropdown"不起作用。
第一个"下拉"作品! 但是按下"添加其他下拉"将出现一个新的"下拉",但这不再有效,为什么?
<!DOCTYPE html>
<html>
<head>
<title>Dropdown</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.7/css/materialize.min.css">
</head>
<body>
<a class='dropdown-button btn' href='#' data-activates='dropdown2'>Drop Me!</a>
<!-- Dropdown Structure -->
<ul id='dropdown2' class='dropdown-content'>
<li><a href="#!">one</a></li>
<li><a href="#!">two</a></li>
<li class="divider"></li>
<li><a href="#!">three</a></li>
</ul>
<hr><hr>
<button class="puthere">Add other Dropdown</button>
<hr><hr>
<div id="drophere"></div>
<div id="repository" style="display: none;">
<div class="exemple">
<!-- Dropdown Trigger -->
<a class='dropdown-button btn' href='#' data-activates='dropdown1'>Drop Me!</a>
<!-- Dropdown Structure -->
<ul id='dropdown1' class='dropdown-content'>
<li><a href="#!">one</a></li>
<li><a href="#!">two</a></li>
<li class="divider"></li>
<li><a href="#!">three</a></li>
</ul>
</div>
</div>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.7/js/materialize.min.js"></script>
<script>
$(document).ready(function() {
$(".puthere").on("click", puthere);
function puthere() {
let $clone = $("#repository .exemple").clone(true);
$clone.appendTo($("#drophere"));
}
});
</script>
</body>
</html>
&#13;