Jquery 在可编辑文本框中将行从一个表复制到另一个表
如果在第一个表中选中该复选框,我想将行从一个表复制到另一个表。我能用下面的代码复制数据。但问题是我希望数据位于可编辑文本框中,以便编辑复制的数据。请帮帮我。。我试着搜索了很多,但没有找到任何有用的东西Jquery 在可编辑文本框中将行从一个表复制到另一个表,jquery,html,jsp,Jquery,Html,Jsp,如果在第一个表中选中该复选框,我想将行从一个表复制到另一个表。我能用下面的代码复制数据。但问题是我希望数据位于可编辑文本框中,以便编辑复制的数据。请帮帮我。。我试着搜索了很多,但没有找到任何有用的东西 $(document).ready(function() { $('#add').on("click", function() { var copiedRow = $('#table1 tbody input:checked').parent().parent().cl
$(document).ready(function() {
$('#add').on("click", function() {
var copiedRow = $('#table1 tbody input:checked').parent().parent().clone();
$('#table2 tr:first').after(copiedRow);
});
});
下面是JSP表1中的代码
<c:if test="${!empty asilList}">
<table id="table1">
<tr>
<th>Select</th>
<th>HARA ID</th>
<th>Vehicle Condition(V)</th>
<th>Environmental Condition(E)</th>
<th>Driving Conditions</th>
<th>Scenario</th>
<th>E</th>
<th>Situation/Condition for Exposure</th>
<th>C</th>
<th>Controllability</th>
<th>S</th>
<th>Severity</th>
<th>ASIL</th>
<th>Remarks</th>
</tr>
<c:forEach items="${asilList}" var="a" varStatus="status">
<tr>
<td><input type="checkbox"></td>
<td>${a.haraId}</td>
<td>${a.scenario.vehicleCondition.vehicleCondition}</td>
<td>${a.scenario.environmentalCondition.environmentalCondition}</td>
<td>${a.scenario.drivingCondition.drivingCondition}</td>
<td>${a.scenario.scenario}</td>
<td>${a.exposure.exposure}</td>
<td>${a.exposure.remark}</td>
<td>${a.controllability.controllability}</td>
<td>${a.controllability.remark}</td>
<td>${a.severity.severity}</td>
<td>${a.severity.remark}</td>
<td>${a.asil}</td>
<td></td>
</tr>
</c:forEach>
</table>
</c:if>
表2
<table id="table2">
<tr>
<th>Select</th>
<th>HARA ID</th>
<th>Vehicle Condition(V)</th>
<th>Environmental Condition(E)</th>
<th>Driving Conditions</th>
<th>Scenario</th>
<th>E</th>
<th>Situation/Condition for Exposure</th>
<th>C</th>
<th>Controllability</th>
<th>S</th>
<th>Severity</th>
<th>ASIL</th>
<th>Remarks</th>
<tr>
<td><input type="checkbox"></td>
<td><input type="text"></td>
<td><select>
<optgroup label="Vehicle Conditions">
</optgroup>
</select></td>
<td><select>
<optgroup label="Environmental Conditions">
</optgroup>
</select></td>
<td><select>
<optgroup label="Driving Conditions">
</optgroup>
</select></td>
<td><select>
<optgroup label="Scenarios">
</optgroup>
</select></td>
<td><select>
<optgroup label="Exposure">
</optgroup>
</select></td>
<td><input type="text"></td>
<td><select>
<optgroup label="Controllability">
</optgroup>
</select></td>
<td><input type="text"></td>
<td><select>
<optgroup label="Severity">
</optgroup>
</select></td>
<td><input type="text"></td>
<td><input type="text"></td>
<td><input type="text"></td>
</tr>
</table>
试试下面
$document.readyfunction{
$'add'.onclick,函数{
var copiedRow=$“table1 tbody输入:已选中”。parent.parent.clone;
var firstRow=$copiedRow.find'td span:eq0'。文本;
$“表2 tbody”。附录如下图所示
$'table2 tbody tr td:eq1'.empty.append
};
};
Php
滑动分页
你没有提供足够的信息来准确回答你的问题。我只是在猜测我的解决方案。您说过希望将该行复制到一个可编辑的文本框中,从代码中可以看出,您希望该代码位于第二个表的第二行中。好了,给你
将$'table1 tbody input:checked'.parent.parent写入控制台,并确保它是否出现right@AnovaConsultancy谢谢你的及时回复。我想你误解了我的问题。我可以用我的代码复制数据。但是我想把这些数据放在第二个表格的文本框中。这样,如果我想在第二个表中进行编辑,我就可以进行编辑。你也可以发布HTML吗?谢谢你的回复。但是我正在复制一行,该行在表2中的行索引[1]处有14列。表2没有任何预先存在的文本框。所以我想要的是:动态创建一行,其中有14列,在表2中有文本框,并将数据从表1复制到这些文本框中的表2中。希望我清楚。好的,我更新了它,将表1中的每一行html复制到文本框内的表2中的每一行中,并将它们格式化为单独的colun。感谢您迄今为止的帮助。使用您的脚本,我只在一个文本框中获取所有14列数据。数据上有标签。。您能解决这个问题吗请澄清:您只需要表1中每个选中行的文本?顺便说一句:每列已经有一个单独的文本框。再看一看是的,你是对的,我想要表1中每个选中行的文本。但每行大约有14列。使用您的脚本,我只能从每行复制第一列数据。需要明确的是:它只为每一行生成一个文本框,但它应该为表2中的每一行生成14列。谢谢你的回答,但这不是我想要的:@Ishan好的,从你的问题我猜这是你想要的。希望有人能更好地帮助你。享受编码
$(document).ready(function() {
$('#add').on("click", function() {
$('#table2 tbody').empty();
var $newrow,
$newcolumn;
$('#table1 tbody input:checked').parent().parent().each(function() {
$newrow = $('<tr></tr>').appendTo($('#table2 tbody'));
$("td", this).each(function() {
if($("input", this).length == 0) {
$newcolumn = $("<td><input type='text' /></td>").appendTo($newrow);
$("input", $newcolumn).val($(this).text());
}
});
});
});
});