jQuery remove HTML table column

后端 未结 11 1397
粉色の甜心
粉色の甜心 2020-12-13 07:13

I have a HTML table like this:

DE
11条回答
  •  粉色の甜心
    2020-12-13 07:53

    Try this:

        $("a.delete").click(function(){
            var td=$(this).parent();
            var col=$(td).text();
            col=col.substring(col.length-2)*1;
            var f="td:nth-child("+col+")";
            var tbl=$(td).parent().parent();
    
            $(tbl).find("tr").each(function(){
                $(this).find(f).hide();
            });
    

    Tested in FF3.5.

    there is one concern though getting column number. If number of columns excede 2 digits it will not work. It would be better if you put custom attribute and assign it position of column.

       ...
    

    remember with nth-child index starts at 1

提交回复
热议问题