[英]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.