我使用 JavaScript 计数器为 Wordpress 创建了一个简码。
后端- 计数器工作正常:
前端- 计数器不起作用(没有控制台错误...):
我的简码代码:
// Delivery Counter Time
function bb__delivery_counter_function() {
?>
<script type='text/javascript'>
if (document.getElementById('countdownTimer')) {
pad = function(n, len) { // leading 0's
var s = n.toString();
return (new Array( (len - s.length + 1) ).join('0')) + s;
};
var timerRunning = setInterval(
function countDown() {
var target = 12; // 12:00hrs is the cut-off point
var now = new Date();
//Put this in a variable for convenience
var weekday = now.getDay();
if(weekday == 0){//Sunday? Add 24hrs
target += 24;
}//keep this before the sunday
if(weekday == 6){//It's Saturday? Add 48hrs
target += 48;
}
//If between Monday and Friday,
//check if we're past the target hours,
//and if we are, abort.
if((weekday>=1) && (weekday<=5)){
if (now.getHours() > target) { //stop the clock
target += 24;
}
}
当我在 Elementor 主题中添加短代码时,“后端”中的一切都工作正常,因此计数器在 Elementor 管理视图中计数。
但如果我尝试通过前端访问该页面,Javascript 将无法工作。有什么想法为什么会发生这种情况吗?
桃花长相依