table中移动tr标签后时间重排
操作效果
主要思路
*获取所有 tr 标签对开始时间和节目时长的值进行获取
*循环对每个 tr 标签进行时间计算
/**
* 时间重排测试
*/
function timeAuto(obj) {
var objs = obj.parentNode.parentNode.parentNode.previousSibling.parentNode.childNodes;
var baseTime = "08:00:00"; //起始时间
var data = $("#broaddate").val(); //用户设定 的哪一天播放
for (var i=2;i<objs.length;i++) {
var obj = objs[i-1].childNodes[6]; //上一个的开始时间对应的 tb
var obj2 = objs[i-1].childNodes[7].nextSibling.innerText; //上一个的文件时间
var obj3 = objs[i].childNodes[6]; //当前要更改的tb
var beginTime = $(obj).text();
var fileLength = obj2;
//console.log("开始时间:"+beginTime+"文件时长:"+fileLength)
var dataTime = $(obj).attr("name"); //用户设定的 播放间隔
var time = getTimeAuto(data+" "+baseTime,beginTime,fileLength,dataTime);
$(obj3).html(time);
}
}
//时间处理函数
function getTimeAuto(intervaltime,beginTime,fileLength,dataTime){
var basenum = 5; //5秒钟延迟播放
var seconds =0;
if(beginTime!=null&&beginTime!=""){
var H3 = parseInt(beginTime.split(":")[0]);
var M3 = parseInt(beginTime.split(":")[1]);
var S3 = parseInt(beginTime.split(":")[2]);
seconds += H3 * 3600 + M3 * 60 + S3 ;
}
if(fileLength!=null &&fileLength !=""){
var H = parseInt(fileLength.split(":")[0]);
var M = parseInt(fileLength.split(":")[1]);
var S = parseInt(fileLength.split(":")[2]);
seconds += H * 3600 + M * 60 + S ;
}
if(dataTime!=null &&dataTime!=""){
var H = parseInt(dataTime.split(":")[0]);
var M = parseInt(dataTime.split(":")[1]);
var S = parseInt(dataTime.split(":")[2]);
seconds += H * 3600 + M * 60 + S ;
}
var Se = seconds-28800+basenum; //减去8小时在加上5秒的延时
var restData = addTime(intervaltime,Se); //后面的是:前一个tr标签的播放开始时间+文件时长-08:00:00(28800s)+间隔时间
var nule = restData.toString().split(" ")[1];
if(nule!=null &&nule.length>0){
var H,M,S;
H = parseInt(nule.split(":")[0]);
M = parseInt(nule.split(":")[1]);
S = parseInt(nule.split(":")[2]);
if(H<9){
H = '0'+H;
}
if(M<9){
M = '0'+M;
}
if(S<9){
S = '0'+S;
}
nule = H+":"+M+":"+S;
}
return nule;
}