$("th").live("click",function(){
var str1="",str2="";
$(this).siblings().each(function(){
if(str1==""){
str1=$(this).attr("orderField");
}
else{
str1=str1+","+$(this).attr("orderField");
}
if(str2==""){
str2=$(this).attr("class");
}
else{
str2=str2+","+$(this).attr("class");
}
});
$("*[name='orderField']").val(str1);
$("*[name='orderDirection']").val(str2);
});
var str1="",str2="";
$(this).siblings().each(function(){
if(str1==""){
str1=$(this).attr("orderField");
}
else{
str1=str1+","+$(this).attr("orderField");
}
if(str2==""){
str2=$(this).attr("class");
}
else{
str2=str2+","+$(this).attr("class");
}
});
$("*[name='orderField']").val(str1);
$("*[name='orderDirection']").val(str2);
});
本文介绍了一种使用jQuery实现表格排序的方法。通过监听表格头部的点击事件,收集所有需要排序的字段及其对应的排序方向,然后将这些信息传递给表单元素以触发排序操作。此方法适用于需要动态排序功能的网页应用。
3502

被折叠的 条评论
为什么被折叠?



