因此,我有一个祷告时间脚本,我想将其嵌入到wordpress页面中。
这是它的链接:http://praytimes.org/manual/

基本上,我尝试将PrayTimes.js文件包含到header.php / page.php文件中,但没有成功。

我将在常规HTML页面中发布的代码如下所示:

<!DOCTYPE html>
<html>
<head>
    <title> Daily Prayer Timetable </title>
    <style>
        body, td, th {font-family: verdana; font-size: 12px; color: #404040;}
        #timetable {border-width: 1px; border-style: outset; border-collapse: collapse; border-color: gray; width: 9em;}
        #timetable td, #timetable th {border-width: 1px; border-spacing: 1px; padding: 2px 4px; border-style: inset; border-color: #CCCCCC;}
        #timetable th {color:black; text-align: center; font-weight: bold; background-color: #F8F7F4;}
    </style>
</head>

<body>

<script type="text/javascript" src="../PrayTimes.js"></script>

<br>
<p align="center">Waterloo, ON, Canada<p>
<div align="center" id="table"></div>

<script type="text/javascript">

    var date = new Date(); // today
    var times = prayTimes.getTimes(date, [43, -80], -5);
    var list = ['Fajr', 'Sunrise', 'Dhuhr', 'Asr', 'Maghrib', 'Isha', 'Midnight'];

    var html = '<table id="timetable">';
    html += '<tr><th colspan="2">'+ date.toLocaleDateString()+ '</th></tr>';
    for(var i in list)  {
        html += '<tr><td>'+ list[i]+ '</td>';
        html += '<td>'+ times[list[i].toLowerCase()]+ '</td></tr>';
    }
    html += '</table>';
    document.getElementById('table').innerHTML = html;

</script>

</body>
</html>


我只是不确定如何将其嵌入到Wordpress页面中。我只需要使用一次。

最佳答案

您应该将脚本放在head标记之间。

<!DOCTYPE html>
<html>
<head>
    <title> Daily Prayer Timetable </title>
    <style>
        body, td, th {font-family: verdana; font-size: 12px; color: #404040;}
        #timetable {border-width: 1px; border-style: outset; border-collapse: collapse; border-color: gray; width: 9em;}
        #timetable td, #timetable th {border-width: 1px; border-spacing: 1px; padding: 2px 4px; border-style: inset; border-color: #CCCCCC;}
        #timetable th {color:black; text-align: center; font-weight: bold; background-color: #F8F7F4;}
    </style>
    <script type="text/javascript" src="../PrayTimes.js"></script>
</head>

<body>

<br>
<p align="center">Waterloo, ON, Canada<p>
<div align="center" id="table"></div>

<script type="text/javascript">

    var date = new Date(); // today
    var times = prayTimes.getTimes(date, [43, -80], -5);
    var list = ['Fajr', 'Sunrise', 'Dhuhr', 'Asr', 'Maghrib', 'Isha', 'Midnight'];

    var html = '<table id="timetable">';
    html += '<tr><th colspan="2">'+ date.toLocaleDateString()+ '</th></tr>';
    for(var i in list)  {
        html += '<tr><td>'+ list[i]+ '</td>';
        html += '<td>'+ times[list[i].toLowerCase()]+ '</td></tr>';
    }
    html += '</table>';
    document.getElementById('table').innerHTML = html;

</script>

</body>
</html>

关于javascript - 我不确定如何将Javascript嵌入到Wordpress页面中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10223152/

10-12 12:22