gpt4 book ai didi

javascript - html、js、css 在 jsfiddle 中有效,但在 sharepoint 中无效

转载 作者:行者123 更新时间:2023-11-28 04:19:02 25 4
gpt4 key购买 nike

我有这个,它可以在 jsfiddle ( https://jsfiddle.net/h353rdzx/1/ ) 中使用

但是我将以下内容放在 SharePoint 中,但计数器不显示数字。只是盒子正在显示。我什至在功能之前放了一个警报,它显示了警报。但是当我在函数中放置一个警报时,它不会弹出。有什么想法吗?

<head>
<link href="/SiteAssets/CountDown/CountDown.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
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.getElementById(id);
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('clockdiv', deadline);
</script>
</head>
<body>
<h1>Countdown Clock</h1>
<div id="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>

最佳答案

或者你也可以这样做。

而不是使用 getElementById使用 getElementsByClassName ...

因为我认为您的 Sharepoint 正在为您的 div 生成不同的元素 ID。

看到我还添加了一个class属性到 div <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);
    <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>

关于javascript - html、js、css 在 jsfiddle 中有效,但在 sharepoint 中无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42310141/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com