jQuery: How to count table columns?

前端 未结 15 1495
天命终不由人
天命终不由人 2020-12-28 13:20

Using jQuery, how would you figure out how many columns are in a table?



15条回答
  •  佛祖请我去吃肉
    2020-12-28 13:27

    function(){
        num_columns = 0;
        $("table td]").each(function(){
            num_columns = num_columns + ($(this).attr('colspan') == undefined ? 1 : $(this).attr('colspan'));
        });
        return num_columns;
    }
    

提交回复
热议问题