这就是我的问题。我目前正在使用WordPress,显然是出于安全原因,它不允许使用脚本标记。所以我把它上传到一个单独的服务器上。现在我的问题是,是否可以在Wordpress页面上将该链接的内容显示为一个小部件,或者我在一个或另一个基本问题上犯了一个大错误?
或者换句话说,我必须做什么,才能使这个脚本是可嵌入的。谷歌搜索的结果总是关于如何嵌入内容的解释,而不是如何传递内容的解释。
代码如下:
<html>
<center>
<h3>
<p id="demo"></p>
</h3>
</center>
<script>
var countDownDate = new Date("Dec 13, 2018 00:00:00").getTime();
var x = setInterval(function() {
var now = new Date().getTime();
var distance = countDownDate - now;
if (distance >= 0){
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Display the result in the element with id="demo"
document.getElementById("demo").innerHTML = days + "d " + hours + "h "
+ minutes + "m " + seconds + "s " ;}
// If the count down is finished, write some text
if (distance < 0) {
distance = Math.abs(distance);
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Display the result in the element with id="demo"
document.getElementById("demo").innerHTML = days + "d " + hours + "h "
+ minutes + "m " + seconds + "s " ;
}
}, 1000);
</script>
</html>
发布于 2018-12-06 04:17:49
Wordpress绝对允许使用script标签。您将在您的functions.php文件中添加类似这样的行,以便正确地将脚本添加到Wordpress站点:
wp_enqueue_script ( 'custom-script', get_template_directory_uri() . '/js/custom-script.js' );
https://stackoverflow.com/questions/53639964
复制相似问题