[英]Passing String and variables into function
I am using this javascript countdown clock: https://github.com/nikhiln/Circular-Countdown 我正在使用此JavaScript倒数时钟: https : //github.com/nikhiln/Circular-Countdown
I have got it working fine but now I am trying to pass in variables into its setup to allow me to control it via buttons. 我的工作正常,但现在我尝试将变量传递到其设置中,以允许我通过按钮进行控制。
It is setup via 通过设置
$(".divName").ccountdown(2016,11,24, '10:40');
So Instead of that date I want to pass in variables, for example. 因此,例如,我想传递变量而不是那个日期。
var date = new Date();
var EndTime = new Date(date);
EndTime.setMinutes(date.getMinutes() + 50);
var years = EndTime.getFullYear();
var months = EndTime.getMonth();
months = months + 1;
var days = EndTime.getUTCDate();
var hours = EndTime.getHours();
var minutes = ('0'+EndTime.getMinutes()).slice(-2);
var timeString = " '" + hours + ":" + minutes +"'";
$(".heatingTimer").ccountdown(years,months,days,timeString);
However this approach doesn't work. 但是这种方法行不通。 I am not sure how to pass in the variables in the format that is expeceted. 我不确定如何以指定的格式传递变量。
您的代码很好,您的代码中只有一个错字(或错误),您应该将时间作为字符串传递,并且要添加额外的单引号,删除引号,它应该可以正常工作:
var timeString = hours + ":" + minutes;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.