[英]Replacing a row of a table on click of a checkbox and vice-versa
I am trying to replace an entire row with the other when the checkbox in that row is selected. 当选中该行中的复选框时,我试图用另一行替换整个行。 So in the replaced row, I will be having a checkbox which is selected already, so when I click on the same, it should show me the previous row.
因此,在替换的行中,我将有一个已被选中的复选框,因此当我单击该复选框时,它应显示上一行。
I have tried in many ways but could not achieve. 我已经尝试了许多方法,但未能实现。 Following is my javascript code,
以下是我的JavaScript代码,
function selectPackage(index,t) {
if (t.is(':checked')) {
console.log("Checked condition");
var packageRow=$("#serviceTable tr.defaultPackageRow");
console.log("Package Row :"+packageRow);
$("#serviceTable tr.defaultServiceRow").replaceWith(packageRow);
} else {
console.log("Un-Checked condition");
var serviceRow=$("#serviceTable tr.defaultServiceRow");
console.log("Package Row :"+serviceRow);
$("#serviceTable tr.defaultServiceRow").replaceWith(serviceRow);
}
}
Where index is the index of the checkbox based on the row. 其中index是基于行的复选框的索引。 serviceTable is the Id of my table and defaultServiceRow and defaultPackageRow are the Ids of two different rows which needs to be toggled.
serviceTable是我的表的ID,defaultServiceRow和defaultPackageRow是需要切换的两个不同行的ID。 I do not want to go hiding option.
我不想去隐藏选项。
Any suggestions would be helpful. 任何的意见都将会有帮助。 Thanks in advance.
提前致谢。
Keep the row you want to replace inside a div
tag. 将要替换的行保留在
div
标签内。 Give the tag a id say divId
. 为标签指定一个ID,例如
divId
。 Now use $('#divId').html(packageRow)
and $('#divId').html(serviceRow)
instead of using replaceWith()
method. 现在,使用
$('#divId').html(packageRow)
和$('#divId').html(serviceRow)
代替使用replaceWith()
方法。
See if this works otherwise please provide your html code as well for more clarity. 看看这是否可行,否则也请提供您的html代码,以提高清晰度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.