jQuery UI可排序,如何检查它是否是最后一个tr并移除类
jQuery UI sortable, how to check if its the last tr and remove class
我有一个选项卡,其中有一个使用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');
希望这能帮助。。。
相关文章:
- 尝试使用Javascript正则表达式来获取“&"分隔文本,无论它是否's是最后一个值
- 将OnClick函数设置为<ul>,最后一个ul是擦除第一个ul-s
- Regex:使用javascript测试最后一个单词后的url中是否存在最后一个斜杠
- 只有最后一个文件是通过迭代形式.submit()操作下载的
- 如何检查值是否是最后一个 CSV 条目
- 如何检查新克隆的节点是否是javascript中的最后一个节点
- 检查元素是否是DOM中类的最后一个
- 确定两个字符串中的一个是否是另一个StringJavascript的子字符串
- NodeJS默认参数,当最后一个参数是回调时
- 检查最后一个字符是否是javascript中的问号
- 如何检查它是否是最后一个元素
- 检测元素的innerHTML的最后一个字符是否为"1",如果是,下划线并将最后一个字符设置为绿色,并
- 确定元素是否是最后一个可见元素
- 有人能解释一下下面javascript代码的最后一个输出是如何产生的吗
- jQuery UI可排序,如何检查它是否是最后一个tr并移除类
- Javascript-如果URL字符串的最后一个字符是“”+"然后把它取下来
- 如何检查日期是否是一个月的最后一天
- 当使用Javascript迭代JSON时…返回的最后一个键是"remove"
- 检查最后一个字符是否为连字符(-),如果不是则添加它
- 检查当前迭代的元素是否是最后一个元素