我想获得有关我的 jquery 的帮助。我对 HTML 元素中这些时间的返回值有疑问。我正在计算时间 1 和时间 2 之间的时间,它将持续多长时间,例如:下午 4:30 带走下午 6:30,返回值为 2.00。
下面是 HTML 的样例:
<span id='time1'>4:30 PM</span> - <span id='title1'>The Scorpion King</span><br></br>
<span id='time2'>6:30 PM</span> - <span id='title2'>Gone in Sixty Seconds</span><br></br>
<span id='time3'>9:00 PM</span> - <span id='title3'>The Fast and the Furious</span><br></br>
<span id='time4'>11:30 PM</span> - <span id='title4'>The Fast and the Furious</span><br></br>
<span id='time5'>2:00 AM</span> - <span id='title5'>The Scorpion King</span><br></br>
<span id='time6'>4:00 AM</span> - <span id='title6'>New Sheer Cover Studio mineral makeup</span><br></br>
<span id='time7'>8:49 PM</span> - <span id='title7'>Tamra's O.C. Wedding</span><br></br>
在这种情况下,我有一个返回值,当我计算出应该在 2 小时内显示“2.00”的返回值时,它将从 time1 和 time2 显示“-10.00”。还有其他值可以做同样的事情,这会让我混淆时间将持续几个小时。我对任何其他返回值都没有问题,当我在不同的时间锻炼时,我会得到 1.00、1.30、2.00、2.30..等。我想计算出它会持续多长时间而不得到返回值'-10.00','-11.00'或任何使用类似'1.00','2.00'的东西, '3.00'...等之前做某事。
我已经尝试过这样的代码,但它会得到错误的返回值,例如“-10.00”、“-11.00”或任何它应该是 1.00、2.00 或其他的东西。
function getSchedule($link,j)
{
var widthval = 850;
var parts = $link.split("/");
var links = parts[parts.length-1];
var programlength = 0;
$.ajax({
url:$.trim(links),
type:'GET',
data:'',
success: function(data)
{
var $data = $(data);
var title1 = $data.filter("#title1").html();
var title2 = $data.filter("#title2").html();
var time1 = $data.filter("#time1").html();
var time2 = $data.filter("#time2").html();
time1 = time1.split(" ");
var time1AMPM = time1[1];
time1 = time1[0].split(":");
time1= time1[0]+'.'+time1[1];
if($.trim(time1AMPM) == 'AM' && time1<12)
time1 = parseFloat(time1)+12;
else if($.trim(time1AMPM) == 'PM' && time1<12)
time1 = parseFloat(time1)+12;
time2 = time2.split(" ");
var time2AMPM = time2[1];
time2 = time2[0].split(":");
time2= time2[0]+'.'+time2[1];
if($.trim(time2AMPM) == 'AM' && time2<12)
time2 = parseFloat(time2)+12;
else if($.trim(time2AMPM) == 'PM' && time2<12)
time2 = parseFloat(time2)+12;
var difftime2time1 = (parseFloat(time2) - parseFloat(time1)).toFixed(2);
var difftime3time2 = (parseFloat(time3) - parseFloat(time2)).toFixed(2);
if(isNaN(difftime2time1))
{
difftime2time1=0;
}
if(isNaN(difftime3time2))
{
difftime3time2=0;
}
var currenttotal = 0;
var firstele = ((j-1)*1)+1; // how many programme i want to output in per block
var lastele = parseInt(firstele)+1; // how many programme i want to output AFTER the firstele
var k = 1;
var programlength = 0;
for(;firstele <= lastele;firstele++)
{
var nexttimedate = parseInt(k)+1;
var programlength = eval('difftime'+nexttimedate+'time'+k);
//alert(programlength);
if(programlength >= 1.00 && programlength <= 1.29)
{
$('#programe'+firstele).addClass("span1hr");
width[j]=517;
}
if(programlength >= 1.30 && programlength <= 1.80)
{
$('#programe'+firstele).addClass("span1_5hr");
width[j]=784;
}
if(programlength >= 1.81 && programlength <= 1.99)
{
$('#programe'+firstele).addClass("span2hr");
width[j]=784;
}
if(programlength >= 2.00 && programlength <= 2.29)
{
$('#programe'+firstele).addClass("span2hr");
width[j]=1051;
}
if(programlength >= 2.30 && programlength <= 2.80)
{
$('#programe'+firstele).addClass("span2_5hr");
width[j]=1318;
}
//sort this out--------1 hour
if(programlength >= 13.00 && programlength <= 13.29)
{
$('#programe'+firstele).addClass("span1hr");
width[j]=517;
}
//sort this out--------1 hour and 30 mins
if(programlength >= 13.30 && programlength <= 13.80)
{
$('#programe'+firstele).addClass("span1_5hr");
width[j]=517;
}
//sort this out--------2 hour
if(programlength >= 14.00 && programlength <= 14.29)
{
$('#programe'+firstele).addClass("span2hr");
width[j]=1585;
}
//sort this out-------- 2 hours and 30 mins
if(programlength >= 14.30 && programlength <= 14.80)
{
$('#programe'+firstele).addClass("span2_5hr");
width[j]=1585;
}
if(programlength == -10.00) //sort this out ---- 2 hour program
{
$('#programe'+firstele).addClass("span2hr");
width[j]=1051;
}
currenttotal++;
pgmcontent[firstele] = eval('title'+k);
k++;
}
checksum+=j;
if(checksuminit == checksum)
{
for(var ii=1;ii<width.length-1;ii++)
{
widthval+=width[ii];
}
for(var jj=1;jj <= pgmcontent.length-1;jj++)
{
$('#programe'+jj).html(pgmcontent[jj]);
}
for(var kk=1;kk <= imagecontent.length-1;kk++)
{
$('#image'+kk).html(imagecontent[kk]);
}
$("body").find('.rowSubPgm').each(function(index) {
$(this).css( "width", widthval+"px");
});
}
}
});
}
我无法发布 jsfiddle 以作为示例显示,因为当我按时锻炼时不会显示警报。不过,我很高兴发布我的网站链接,这样您就可以看到具有差异值“1.00、2.00、“13.00”、“14.00”和“-10.00”的警报消息。你会知道我在说什么。
我的网站链接: