jQuery UI可排序,如何检查它是否是最后一个tr并移除类

jQuery UI sortable, how to check if its the last tr and remove class

本文关键字:最后一个 是否是 tr 检查 排序 UI 何检查 jQuery      更新时间:2023-09-26

我有一个选项卡,其中有一个使用sortable进行拖放排序的表单,它还有上下箭头,可以单击它们上下移动行。生成表格时,我会隐藏第一行的向上箭头和最后一行的向下箭头。但是,当拖放或使用箭头上下移动行时,不会更新上下箭头。如何解决此问题:

function sortt() {
    $("#table_or tbody tr:first").find(".moveUp").hide();
    $("#table_or tbody tr:last").find(".moveDown").hide();
    $("#table_or tbody tr").each(function(){              
        $idx = $("#table_or tbody tr").index(this)+1;
        $(this).find("input[name$=_order]").val($idx); 
        $(this).children("td").eq(2).html("Order: "+$idx);

        //updates zebra 
        $("#table_or tbody tr:odd").removeClass().addClass("zebra2");
        $("#table_or tbody tr:even").removeClass().addClass("zebra1"); 
       //Check if the custom input exists
        if($(this).find("input.custom_opt").val()!=undefined){    
            $val = $(this).find("input.custom_opt").val(); //get the value
            $val = $val.split("|"); //split the value string into an array
           // var cust_dis = $(this).find("input.cust_dis").val();
           // alert(cust_dis);
            $val[6] = $idx; //Update the order value within the array
            $newVal = "";
            //Loop through the array and recreate delimited string. 
            for( $i=0; $i<$val.length; $i++ ){
                if($i!=0){ $newVal = $newVal+"|"; }
                $newVal = $newVal+$val[$i];
                }
            $(this).find("input.custom_opt").val($newVal); //Give the custom input its updated value.    
            } 
        });
    }

尝试以下代码查找最后一个tr:

      $('#myTableId tr:last').removeClass('className1 ClassName2');

希望这能帮助。。。