JavaScript语法错误,但仅限于IE7/8中
我在IE 7和8中遇到了下面的javascript错误-我得到的错误代码是: 消息:应为“')” 行:1 字符:19 代码:0 令人不快的是:JavaScript语法错误,但仅限于IE7/8中,javascript,internet-explorer,syntax-error,Javascript,Internet Explorer,Syntax Error,我在IE 7和8中遇到了下面的javascript错误-我得到的错误代码是: 消息:应为“')” 行:1 字符:19 代码:0 令人不快的是: var lct_days = 0; var lct_hours = 0; var lct_minutes = 0; var lct_seconds = 0; function calc_data(dateandtime) { dateandtime = datetime.split(" "); tempdate = dateandtim
var lct_days = 0;
var lct_hours = 0;
var lct_minutes = 0;
var lct_seconds = 0;
function calc_data(dateandtime) {
dateandtime = datetime.split(" ");
tempdate = dateandtime[0].split("/");
temptime = dateandtime[1].split(":");
var seconds = 1000;
var minutes = seconds * 60;
var hours = minutes * 60;
var days = hours * 24;
var years = days * 365;
var db_time = new Date(tempdate[0], tempdate[1] - 1, tempdate[2], temptime[0], temptime[1], 00);
var now_time = new Date();
db_time = db_time.getTime();
now_time = now_time.getTime();
var lctresult = db_time - now_time;
lct_years = Math.floor(lctresult / years);
lct_days = Math.floor(lctresult / days) - (lct_years * 365);
lct_hours = Math.floor(lctresult / hours) - (lct_days * 24) - (lct_years * 365 * 24);
lct_minutes = Math.floor(lctresult / minutes) - (lct_hours * 60) - (lct_days * 24 * 60) - (lct_years * 365 * 24 * 60);
lct_seconds = Math.floor(lctresult / seconds) - (lct_minutes * 60) - (lct_hours * 60 * 60) - (lct_days * 60 * 24 * 60) - (lct_years * 365 * 24 * 60 * 60);
singlebox = false;
if (lct_years > 99) {
lct_years = 99;
}
if (lct_days > 99) {
singlebox = true;
}
if (lct_years < 0) lct_years = 0;
if (lct_days < 0) lct_days = 0;
if (lct_hours < 0) lct_hours = 0;
if (lct_minutes > 60) lct_minutes = 60;
if (lct_minutes < 0) lct_minutes = 0;
if (lct_seconds < 0) lct_seconds = 0;
}
function setlct(datetime) {
calc_data(datetime);
if (lct_years == 0) {
jQuery('.LCT').find('div:nth-child(1)').removeClass('hide').addClass('hide');
if (lct_days == 0) {
jQuery('.LCT').find('div:nth-child(2)').removeClass('hide').addClass('hide');
if (lct_hours == 0) {
jQuery('.LCT').find('div:nth-child(3)').removeClass('hide').addClass('hide');
if (lct_minutes == 0) {
jQuery('.LCT').find('div:nth-child(4)').removeClass('hide').addClass('hide');
//if(lct_seconds==0)
//jQuery('.LCT').find('div:nth-child(5)').removeClass('hide').addClass('hide');
}
}
}
}
if (jQuery('.LCT').find('div.type').siblings().length == 5) {
jQuery('.LCT').find('div:nth-child(1) .bg p').html(lct_years);
jQuery('.LCT').find('div:nth-child(2) .bg p').html(lct_days);
jQuery('.LCT').find('div:nth-child(3) .bg p').html(lct_hours);
jQuery('.LCT').find('div:nth-child(4) .bg p').html(lct_minutes);
jQuery('.LCT').find('div:nth-child(5) .bg p').html(lct_seconds);
if (jQuery('.LCT div:nth-child(2)').hasClass('big')) {
if (singlebox == true) jQuery('.LCT div:nth-child(2).big .bg p').addClass("evensmaller");
}
if (jQuery('.LCT div:nth-child(2).medium').hasClass('medium')) {
if (singlebox == true) jQuery('.LCT div:nth-child(2).medium .bg p').addClass("evensmaller");
}
if (jQuery('.LCT div:nth-child(2).small').hasClass('small')) {
if (singlebox == true) jQuery('.LCT div:nth-child(2).small .bg p').addClass("evensmaller");
}
} else {
if (lct_years != 0 && lct_years > 0) {
jQuery('.LCT').find('div .bg p').html(lct_years);
jQuery('.LCT div .type').html('YEARS');
} else if (lct_days != 0 && lct_days > 0) {
jQuery('.LCT').find('div .bg p').html(lct_days);
jQuery('.LCT div .type').html('DAYS');
} else if (lct_hours != 0 && lct_hours > 0) {
jQuery('.LCT').find('div .bg p').html(lct_hours);
jQuery('.LCT div .type').html('HOURS');
} else if (lct_minutes != 0 && lct_minutes > 0) {
jQuery('.LCT').find('div .bg p').html(lct_minutes);
jQuery('.LCT div .type').html('MINUTES');
} else if (lct_seconds != 0 && lct_seconds > 0) {
jQuery('.LCT').find('div .bg p').html(lct_seconds);
jQuery('.LCT div .type').html('SECONDS');
}
if (jQuery('.LCT div:nth-child(1).big').length != 0) {
if (singlebox == true) jQuery('.LCT div:nth-child(1).big .bg p').addClass("evensmaller");
}
if (jQuery('.LCT div:nth-child(1).medium').length != 0) {
if (singlebox == true) jQuery('.LCT div:nth-child(1).medium .bg p').addClass("evensmaller");
}
if (jQuery('.LCT div:nth-child(1).small').length != 0) {
if (singlebox == true) jQuery('.LCT div:nth-child(1).small .bg p').addClass("evensmaller");
}
}
var lctTimer = setInterval("setlct(" + datetime + ");", 1000);
clearTimeout(lctTimer);
}
var lctTimer = '';
jQuery(document).ready(function ($) {
datetime = $('input.lct_datetime').val();
lctTimer = setInterval('setlct(\'' + datetime + '\');', 1000);
});
var lct_天=0;
var lct_小时=0;
var lct_分钟=0;
var lct_秒=0;
函数计算数据(日期和时间){
dateandtime=datetime.split(“”);
tempdate=dateandtime[0]。拆分(“/”;
TENTIME=dateandtime[1]。拆分(“:”);
var秒=1000;
var分钟=秒*60;
var小时=分钟*60;
var天数=小时*24;
var年=天*365;
var db_time=新日期(tempdate[0],tempdate[1]-1,tempdate[2],testime[0],testime[1],00);
var now_time=新日期();
db_time=db_time.getTime();
now_time=now_time.getTime();
var lctresult=db\u时间-现在\u时间;
lct_年=数学下限(lct结果/年);
lct_天数=数学下限(lct结果/天数)-(lct_年*365);
lct_小时=数学楼层(lct结果/小时)-(lct_天*24)-(lct_年*365*24);
lct_分钟=数学楼层(lct结果/分钟)-(lct_小时*60)-(lct_天*24*60)-(lct_年*365*24*60);
lct_秒=数学下限(lct结果/秒)-(lct_分钟*60)-(lct_小时*60*60)-(lct_天*60*24*60)-(lct_年*365*24*60*60);
singlebox=false;
如果(寿命周期>99年){
lct_年=99年;
}
如果(lct_天数>99){
singlebox=true;
}
如果(lct_年<0)lct_年=0;
如果(lct_天数<0)lct_天数=0;
如果(lct_小时<0)lct_小时=0;
如果(lct_分钟>60)lct_分钟=60;
如果(lct_分钟<0)lct_分钟=0;
如果(lct_秒<0)lct_秒=0;
}
函数setlct(日期时间){
计算数据(日期时间);
如果(lct_年==0){
jQuery('.LCT').find('div:nth child(1)).removeClass('hide').addClass('hide');
如果(lct_天数==0){
jQuery('.LCT').find('div:nth child(2')).removeClass('hide').addClass('hide');
如果(lct_小时==0){
jQuery('.LCT').find('div:nth child(3')).removeClass('hide').addClass('hide');
如果(lct_分钟==0){
jQuery('.LCT').find('div:nth child(4')).removeClass('hide').addClass('hide');
//如果(lct_秒==0)
//jQuery('.LCT').find('div:nth child(5')).removeClass('hide').addClass('hide');
}
}
}
}
if(jQuery('.LCT').find('div.type').sides().length==5){
jQuery('.LCT').find('div:nth child(1.bg p')).html(LCT_);
jQuery('.LCT').find('div:nth child(2.bg p')).html(LCT_天);
jQuery('.LCT').find('div:nth child(3.bg p')).html(LCT_小时);
jQuery('.LCT').find('div:nth child(4.bg p')).html(LCT_分钟);
jQuery('.LCT').find('div:nth child(5.bg p')).html(LCT_秒);
if(jQuery('.LCT div:nth child(2)').hasClass('big')){
if(singlebox==true)jQuery('.LCT div:nth child(2).big.bg p').addClass(“evensiller”);
}
if(jQuery('.LCT div:nth child(2.medium').hasClass('medium')){
if(singlebox==true)jQuery('.LCT div:nth child(2.medium.bg p').addClass(“evensiller”);
}
if(jQuery('.LCT div:nth child(2.small').hasClass('small')){
if(singlebox==true)jQuery('.LCT div:nth child(2).small.bg p').addClass(“evensiller”);
}
}否则{
如果(lct_年数!=0&&lct_年数>0){
jQuery('.LCT').find('div.bg p').html(LCT_);
jQuery('.LCT div.type').html('YEARS');
}否则如果(lct_天数!=0&&lct_天数>0){
jQuery('.LCT').find('div.bg p').html(LCT_天);
jQuery('.LCT div.type').html('DAYS');
}否则如果(lct_小时数!=0&&lct_小时数>0){
jQuery('.LCT').find('div.bg p').html(LCT_小时);
jQuery('.LCT div.type').html('HOURS');
}否则如果(lct_分钟数!=0&&lct_分钟数>0){
jQuery('.LCT').find('div.bg p').html(LCT_分钟);
jQuery('.LCT div.type').html('MINUTES');
}否则如果(lct_秒!=0&&lct_秒>0){
jQuery('.LCT').find('div.bgp').html(LCT_秒);
jQuery('.LCT div.type').html('SECONDS');
}
if(jQuery('.LCT div:nth child(1.big').length!=0){
if(singlebox==true)jQuery('.LCT div:nth child(1).big.bg p').addClass(“evensiller”);
}
if(jQuery('.LCT div:n个子项(1.medium')).length!=0){
if(singlebox==true)jQuery('.LCT div:nth child(1.medium.bg p').addClass(“evensiller”);
}
if(jQuery('.LCT div:nth child(1.small').length!=0){
if(singlebox==true)jQuery('.LCT div:nth child(1).small.bg p').addClass(“evensiller”);
}
}
var lctTimer=setInterval(“setlct(“+datetime+”);”,1000);
清除超时(lctTimer);
}
var lctTimer='';
jQuery(文档).ready(函数($){
datetime=$('input.lct_datetime').val();
lctTimer=setInterval('setlct(\''+datetime+'\');',1000);
});
有什么想法吗???我也不确定我犯的错误是什么。。。这似乎没有道理
另外,它是WordPress的实时倒计时时钟插件。不确定,但请尝试更改行:
var lctTimer = setInterval("setlct(" + datetime + ");", 1000);
到
代码审查stackexchange站点会很有帮助,我想您是否尝试过通过jsHint或类似工具运行代码?
var lctTimer = setInterval(function() {
setlct(datetime);
},1000);