getCommonTable.js
//获取table头
function getTableHeadByWidth(widthSize,ids){
var Tableone = "<table cellspacing='0' cellpadding='0' ";
var Tabletwo = ">";
if (widthSize == "")
return Tableone + Tabletwo;
else
return Tableone+"width="+widthSize+Tabletwo;
}
//获取第一个tr td 传一个宽度值
function getTrAndTdFirstByCWidth(classname,widthSize){
var tdone = " <tr ";
var tdtwo = "><td ";
var tdthr = " > ";
if (classname =="")
tdone += tdtwo;
else
tdone+=" class ='"+classname+"' "+tdtwo;
if (widthSize == "")
tdone += tdthr;
else
tdone += " </td><td ";
var tdtwo =">";
if (widthSize =="")
return tdone+tdtwo;
else
return tdone+"width="+widthSize+tdtwo;
}
//获取最后一个td
function getTdLastByWidth(widthSize){
var tdone = " </td><td ";
var tdtwo =">";
if (widthSize =="")
return tdone+tdtwo;
else
return tdone+"width="+widthSize+tdtwo;
}
//获取最后一个tr/td
function getTrAndTdLast(){
return " </td></tr>";
}
//获取table尾
function getTableLast(){
return "</table>";
}
//获取img
function getImgByParams(imgUrl,altstr,eventName,eventParams,imgid){
var one = "<img";
if (imgUrl != "")
one += "src='"+imgUrl+"'";
if (altstr != "")
one += "alt='"+altstr+"'";
if(imgid != "")
one += "id='"+imgid+"'";
one += "onclick='"+eventName+"("+eventParams+");'> ";
return one
}
//--------排序---------------------------
//通过字段的内容排序
SortByBtnidAndCellName=function(btnId,cellName,celltype){
var way = getOpType(btnId);//0为正。1为倒
var ds = userdata.value;
var sortarr= new Array();
if ((ds!= null) && (typeof(ds) == "object")){
var len = ds.Rows.length;
if(celltype=='S' || celltype=='N'){
for(var j=0;j<len;j++){
sortarr[j] = ds.Rows[j][cellName];//.substr(0,1);//通过字符
}
}else if(celltype=='D'){
for(var i=0;i<len;i++){
sortarr[i] = getDateByFormat(ds.Rows[i][cellName]);//通过日期
}
}
if(sortarr!=''){
var indexarr = new Array();
indexarr = getSortArray(sortarr,celltype);//得到新的排序规则
if(indexarr != ''){
setSortAginbyWay(indexarr,way);
}
}
}
}
//获得排序
getOpType=function(btnid){//返回0正序,1为倒序
var imgName= $("#"+btnid).attr("src");
var wz = imgName.indexOf('.gif');
var oldImg =imgName.substr(wz-9,9);
if(oldImg=='sort_desc'){//当前是倒序或未排序,需要正序sort_ascc
$("#"+btnid).attr("src","../Images/sort_ascc.gif");
return 0;
}else{
$("#"+btnid).attr("src","../Images/sort_desc.gif");
return 1;
}
}
//按JS Sort排序 获得新的排序规则
getSortArray=function (sortdatearr,celltype){// 参数为array
var sortstr = '';
for(var k=0;k<sortdatearr.length;k++){
if(sortstr=='')
sortstr=sortdatearr[k];
else
sortstr+='^%^'+sortdatearr[k];
}
var newsortdate =sortdatearr;
var len = sortdatearr.length;
if(celltype =='S' || celltype =='D')
newsortdate.sort();//字符排序
else{ //数字排序
for(var i=0;i<len;i++){
var tmp =0;
for(var j=i+1;j<len;j++){
if(newsortdate[i]>newsortdate[j]){
tmp = newsortdate[i];
newsortdate[i] = newsortdate[j];
newsortdate[j] =tmp;
}
}
}
}
var tmpsortdate =sortstr.split('^%^')
var resultarr = new Array();
for(var i = 0;i<len;i++){
for(var j = 0;j<len;j++){
if(newsortdate[i]==tmpsortdate[j]){
resultarr[i] = j;
tmpsortdate[j] ='||||||||';
break;
}
}
}
return resultarr;
};
//--------------------end-------------------------------
//删除重复的手机号码
SplitRepeatMobile=function(mobile){
var mob=mobile;
for(var i=0;i<mob.length;i++){
for(var j=i+1;j<mob.length;j++){
if(mob[i]==mob[j]){
mob.splice(j,1);
}
}
}
return mob;
}
1
您可能感兴趣的文章: