我在我的网页中有一个表单,该表单由一个表格组成,而该表格又包含一个嵌套表。当我尝试克隆嵌套表的行时,这些行没有被克隆。但是,克隆对于外层表来说工作得很好。这是我的HTML代码
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<div id="division">
<form class="allergyrow">
<table id="tab" border="1">
<thead>
<tr>
<th scope="col">Remove</th>
<th scope="col">Allergy</th>
<th scope="col">Reaction</th>
<th scope="col">Adverse Event Date</th>
<th scope="col">Comment</th>
</tr>
</thead>
<tbody>
<tr class="datarow">
<td><input type = "checkbox" id = "remove" class="remove" value = "Remove" /></td>
<td><input type = "text" id = "myText" class="myText" /></td>
<td >
<div>
<table id="inner" class="inner">
<tbody>
<tr id="innerrow" class="innerrow">
<td>
<select id = "myList" class="myList">
<option value = "1">Rashes</option>
<option value = "2">Shock</option>
<option value = "3">Asthma</option>
<option value = "4">Nausea</option>
<option value = "5">Anemia</option>
<option value = "6">Unknown/Other</option>
</select>
</td>
<td>
<select id = "reaction" class="reaction">
<option>Yes</option>
<option>Mild</option>
<option>Moderate</option>
<option>severe</option>
</select>
</td>
<td>
<button id="plus" class="plus">plus</button>
</td>
</tr>
</tbody>
</table>
</div>
</td>
<td><input type="date" id="eventdate" class="eventdate"/></td>
<td><input type="text" id="comment" class="comment"/></td>
</tbody>
</table>
</form>
<button id="submit">Submit</button>
</div>下面是我用来克隆内部行的Jquery代码
$("#plus").click(function(){
var row=$("#innerrow");
row.clone().appendTo("#inner");
s
});但是JQuery代码似乎不起作用,当我调试时,我可以看到克隆的行正在创建,然后它们就消失了。谢谢。
发布于 2013-07-20 03:00:02
在HTML文档中,不能有两个具有相同ID的元素。ID必须是唯一的。因此,clone()有可能因此而无法工作,您不能拥有两个相同的ID
https://stackoverflow.com/questions/17753493
复制相似问题