//给表头添加单击事件,完成不同排序的切换
var ths=document.getElementsByTagName("th")
for(i=0;i<ths.length;i++){
ths[i].onclick=function(){
var sortname=this.getAttribute("type")
this.flag=this.flag==-1?1:-1
var that=this
userListData.sort(function(a,b){
var x=a[sortname]
var y=b[sortname]
if(x>y){
return that.flag
}else if(x<y){
return -that.flag
}else{
return 0
}
})
var newtbody=creatTbody(userListData)
var oldtbody=document.getElementsByTagName("tbody")[0]
table.replaceChild(newtbody,oldtbody)
}
}