简体   繁体   English

单击复选框替换表格的行,反之亦然

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

相关问题 使用复选框禁用表格行的输入,反之亦然 - Disabling the inputs of a table row with a checkbox and vice versa 对象到字符串,反之亦然 - Object to string, and vice-versa 数据表问题:如何单击复选框,然后突出显示行,反之亦然? - Datatables issue: How can I click a checkbox and then highlight the row and vice versa? 如果我选中所有复选框,则应自动选中“全选”复选框,反之亦然 - If I check all checkboxes the select all checkbox should automatically checked and vice-versa in AngularJS 从左到右淡入文本,反之亦然 - fade in text left to right or vice-versa 将ArrayBuffer转换为Array,反之亦然 - Convert ArrayBuffer to Array and vice-versa 基于HTML创建JSON,反之亦然 - Create JSON on HTML basis and vice-versa 将大写字母转换为小写字母,反之亦然 - Converting uppercase to lowercase, and vice-versa 单击按钮即可更改元素的类,并重命名按钮名称,反之亦然 - Changing an element's class at the click of a button and renaming the button name and vice-versa Reactjs:如何在加载材料表时选中所有行复选框并在单击时取消选择,反之亦然? - Reactjs: How to make all row checkbox checked true when material table is loaded and deselect when clicked and vice versa?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM