[英]In jquery, how can I write a function to copy the height of one DIV to another DIV once?
[英]how can I add a copy of a div with jquery?
我有一个包含一些动态生成的下拉列表的div。
我要克隆此文件并将其添加到原始文件的下面。 原始代码为:
<div id="subjectselectiondiv" style="width:inherit;">
<h4>Select the subjects that you are able to tutor</h4>
<div id='choices'>
<script type="text/javascript">
var doc = document.getElementById("choices");
var subj_div = document.createElement('div');
subj_div.setAttribute('class', 'selectSearchBar');
subj_div.innerHTML = '<select id="level'+counter+'" name="level'+counter+'" class="selectSearchBar"><?php echo "<option>Level</option>"; while($row = mysqli_fetch_array($result_level, MYSQLI_ASSOC)){echo "<option value=".$row['id'].">".$row['level']."</option>";}?></select><div id="subject'+counter+'" style="display:inline;">sBar2</div><div id="topic'+counter+'" style="display:inline;">sbar3</div>';
doc.appendChild(subj_div);
</script>
<a href='#' class="more" onclick="Repeat()">Add another subject</a>
</div>
我认为功能Repeat()可以使用:
function Repeat(){
counter++;
$('#choices').clone().appendTo('#subjectselectdiv');
event.preventDefault();
}
但这不起作用-我错过了什么吗?
谢谢
名称不匹配:
<div id="subjectselectiondiv" style="width:inherit;">
^^^^^^
$('#choices').clone().appendTo('#subjectselectdiv');
^^^
您要附加的内容不存在。 最有可能的是,如果您不愿检查JavaScript控制台,就会看到有关不存在元素的警告/错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.