我有这个,它适用于jsfiddle(https://jsfiddle.net/h353rdzx/1/)
但是我将以下内容放在SharePoint中,但计数器没有显示该数字。只是盒子正在显示。我甚至在功能之前发出警报并显示警报。但是当我在函数内部发出警报时,它就不会弹出。有什么想法吗?
db = MySQLdb.connect(host=DB_HOST, user=DB_USER, passwd=DB_PASS,
db=DB_NAME, charset="utf8", use_unicode=True)
答案 0 :(得分:0)
或者你可以做到。
而不是使用getElementById
使用getElementsByClassName
...
因为我认为您的Sharepoint正在为您生成不同的元素ID。
看到我还为div class
添加了<div id="clockdiv" class="js-clockdiv">
属性,并且还更改了对initializeClock('js-clockdiv', deadline);
的调用
var endtime = '4/29/2017';
function getTimeRemaining(endtime) {
var t = Date.parse('4/29/2017') - Date.parse(new Date());
var seconds = Math.floor((t / 1000) % 60);
var minutes = Math.floor((t / 1000 / 60) % 60);
var hours = Math.floor((t / (1000 * 60 * 60)) % 24);
var days = Math.floor(t / (1000 * 60 * 60 * 24));
return {
'total': t,
'days': days,
'hours': hours,
'minutes': minutes,
'seconds': seconds
};
}
alert('test');
function initializeClock(id, endtime) {
var clock = document.getElementsByClassName(id)[0];
var daysSpan = clock.querySelector('.days');
var hoursSpan = clock.querySelector('.hours');
var minutesSpan = clock.querySelector('.minutes');
var secondsSpan = clock.querySelector('.seconds');
function updateClock() {
var t = getTimeRemaining(endtime);
daysSpan.innerHTML = t.days;
hoursSpan.innerHTML = ('0' + t.hours).slice(-2);
minutesSpan.innerHTML = ('0' + t.minutes).slice(-2);
secondsSpan.innerHTML = ('0' + t.seconds).slice(-2);
if (t.total <= 0) {
clearInterval(timeinterval);
}
}
updateClock();
var timeinterval = setInterval(updateClock, 1000);
}
var deadline = new Date(Date.parse(new Date()) + 15 * 24 * 60 * 60 * 1000);
initializeClock('js-clockdiv', deadline);
&#13;
<head>
<link href="/SiteAssets/CountDown/CountDown.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Countdown Clock</h1>
<div id="clockdiv" class="js-clockdiv">
<div>
<span class="days"></span>
<div class="smalltext">Days</div>
</div>
<div>
<span class="hours"></span>
<div class="smalltext">Hours</div>
</div>
<div>
<span class="minutes"></span>
<div class="smalltext">Minutes</div>
</div>
<div>
<span class="seconds"></span>
<div class="smalltext">Seconds</div>
</div>
</div>
</body>
&#13;
答案 1 :(得分:0)
此代码有效。无论我做什么,我都无法获得在SharePoint中使用的原始代码或建议代码。
<div id='clockCountDown'></div>
<script>
function countdown(id,endtime){
var timer=setInterval(function () {
var t = endtime - new Date();
if (t>0) {
var HTML='{0:D2} days {1:HH}:{1:mm}:{1:ss}';
document.getElementById(id).innerHTML = String.format(HTML,~~(t/864e5),new Date(t));
} else {
clearInterval(timer);
}
}, 1000);
return(timer);
};
var timer1=countdown('clockCountDown' , new Date('4/29/2017'));
</script>