简体   繁体   English

JavaScript声明问题

[英]Javascript declaration issue

//PROBLEM SOLVED// It turned out that the JQuery Ajax call couldn't reach the URL in certain browsers. //问题已解决//事实证明,在某些浏览器中,JQuery Ajax调用无法到达URL。

Thanks anyway guys, for your quick responses, definitly helped to work it out. 无论如何,谢谢大家的快速响应,他们一定会帮助您解决问题。

Sorry for the non-specific title, I don't even think what should be the problem. 抱歉,标题不明确,我什至不认为这应该是问题所在。

There is a JQuery plugin ( http://keith-wood.name/countdown.html ) which counts down from a specific date or time. 有一个JQuery插件( http://keith-wood.name/countdown.html ),它从特定日期或时间开始递减计数。

The end time from which the counter should start can be defined in 2 ways: either setting a date either setting the number of seconds left. 可以从2种方式定义计数器应从其开始的结束时间:设置日期或设置剩余秒数。

My project needs the second one and based on the documentation this option has to be declared like: 我的项目需要第二个项目,根据文档,必须将此选项声明为:

$('#digital_hour').countdown({until: +300});

Notice the "+" sign before the number. 注意数字前面的“ +”号。

It works nice on any OS and device, UNTIL I replace the number 300 with a variable that stores the seconds left until the end of the day on the server. 它可以在任何操作系统和设备上正常工作,直到我用一个变量替换数字300为止,该变量存储了直到一天结束之前在服务器上剩余的秒数。 So this version: 所以这个版本:

$('#digital_hour').countdown({until: +seconds_left_on_server});

works on specific browsers, but on others don't. 适用于特定的浏览器,但不适用于其他浏览器。 Strangly enought it works under my Vista/Mozilla20.0 combo, but it doesn't on my Vista/IE6, nor on my friends Ubuntu/Mozilla combo. 不足为奇的是,它可以在我的Vista / Mozilla20.0组合中使用,但不能在我的Vista / IE6或我的朋友Ubuntu / Mozilla组合中使用。

I'm not a huge javascript admirer, nor an expert on the subject, but I feel that there is something around the "+" sign. 我既不是JavaScript的崇拜者,也不是该主题的专家,但是我觉得“ +”号周围有些东西。

Can anyone help? 有人可以帮忙吗?

您可以尝试

$('#digital_hour').countdown({until: new Date(+(new Date()) + 1000 * seconds_left_on_server)});

Have you tried something simple like var seconds_left = 300 and then $('#digital_hour').countdown({until: +seconds_left}); 您是否尝试过类似var seconds_left = 300然后$('#digital_hour').countdown({until: +seconds_left}); and see what happens? 看看会发生什么?

It sounds like your variable is not storing what it should. 听起来您的变量没有存储应有的值。 The "+" shouldn't be a problem. “ +”应该没有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM