gpt4 book ai didi

javascript - 在 jquery 中追加行时重复

转载 作者:行者123 更新时间:2023-11-28 03:21:31 24 4
gpt4 key购买 nike

enter image description here我是 jquery 和 javascript 的新手。请帮我解决这个错误。单击复选框(超过 3 次)时,它会多次附加单元格。提前致谢。请帮我。 * 它多次附加单元格

function suma()
{
alert("hi");
$('#one').on("click", function(){
$('#one input:checked').parent().parent().appendTo("#two");
$("#two tr").append("<td> a </td>","<td> b</td>","<td> c</td>");
});
}
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>
</head>
<body>

<input type="submit" value="submit" onclick="suma()"/>

<table id="one" border="1">
<tr>
<td> <input type="checkbox"></td>
<td>1</td>
<td> 2</td>
</tr>
<tr>
<td> <input type="checkbox"></td>
<td> 3</td>
<td> 4</td>
</tr>
<tr>
<td> <input type="checkbox"></td>
<td> 5</td>
<td> 6</td>
</tr>
<tr>
<td> <input type="checkbox"></td>
<td>7</td>
<td> 8</td>
</tr>
<tr>
<td> <input type="checkbox"></td>
<td>9</td>
<td>10</td>
</tr>
<tr>
<td> <input type="checkbox"></td>
<td>11</td>
<td>12</td>
</tr>

</table>
<table id="two" border="1">
<th> msg1</th>
<th> msg2</th>
<th> msg3</th>
<th> msg4</th>
<th> msg5</th>
<th> msg6</th>
</table>
</body>
</html>

最佳答案

试试这个,

function suma() {
$('#one').on("click", function() {
var appendStr = "<td> a </td><td> b</td><td> c</td>";
$('#one input:checked').parent().parent().wrap("<tr></tr>")
.append(appendStr).appendTo("#two");
// add string inside TR and append the a b c then appendTo table.
});
}

工作 example

希望有所帮助,

关于javascript - 在 jquery 中追加行时重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45187320/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com