我一直在尝试学习构建网站,并且我遇到了一个我似乎无法找到答案的问题。我希望#buttonNewNote在单击时创建#cloneBox的副本,但似乎无法弄清楚。谢谢!单击按钮时如何创建元素的副本
代码
<html>
<body>
<div id='navbar'>
<div id='siteTitle'>
<h1> Notes.com </h1>
<button id= 'buttonNewNote'> New Note </button>
</div>
</div>
<div class='cloneBox'>
<textarea rows="4" cols="50">Enter your notes Here! </textarea>
</div>
</body>
</html>
CSS
.cloneBox {
top: 200px;
left:50px;
display: -webkit-flex;
border: 5px;
border-top: 20px;
border-style: solid;
border-color: yellow;
width:260px;
}
#noteInput {
position: relative;
min-width: 50px;
width: 200px;
height: 100px;
border: 5px;
border-top: 20px;
border-color: #3296d2;
}
我Jquery的
什么$(document).ready(function() {
$('.cloneBox').draggable();
$('#buttonNewNote').click(function(){
$(document.createElement('div'));
$('div').html('<textarea rows="4" cols="50">Enter your notes Here!
</textarea>')
$('div').addClass('cloneBox')
});
});
太谢谢你了!
您需要使用'的clone()' –