添加php代码时不会包含jQuery源文件

时间:2015-07-20 18:28:05

标签: php jquery

代码运行良好,但在我添加了下面的PHP代码之后,它们都崩溃了。它说"未能加载资源"对于jquery-1.11.3.js之后我添加了php代码,如下所示。 我完全迷失在这里。不知道这里有什么不对。

<?php
    $currentMonthInInteger = date("n");
    $currentYear = date("Y");

    $timestamp = mktime(0, 0, 0, $currentMonthInInteger, 1, $currentYear);

    $totalday = date("t", $timestamp);
    $thismonth = getdate($timestamp);
    $firstday = $thismonth['wday'] - 1;

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" 
"http://www.w3.org/TR/REC-html40/loose.dtd">
    <html>
        <head>
            <meta charset="utf-8" />
            <title>CALENDAR</title>
            <script type="text/javascript" src="include/jquery-1.11.3.js"></script>

            <style>

                table{
                    position: relative;
                    border: 1px solid black;
                    height: 400px;
                    width: 700px;
                    table-layout: fixed;
                    border-collapse: collapse;
                }

                td{
                    display: inline;
                    border: 1px solid black;
                    position: static;
                    text-align: center;
                    font-size: 1.5em;
                    padding: 12px 20px;
                    height: 57px;
                }

                #head{
                    height: 57px;
                }
                caption{
                    font-size: 2.2em;
                }

            </style>    
        </head>


    <body>

        <div id="main" align = "center">
            <table id="ref">
            <!--<tr>-->
                <caption id="month">JULY</caption>
            <!--</tr>-->

                    <tr id="head">
                        <th>MON</th>
                        <th>TUE</th>
                        <th>WED</th>
                        <th>THU</th>
                        <th>FRI</th>
                        <th>SAT</th>
                        <th>SUN</th>
                    </tr>

                    <tr>
                        <td><span id = 0>00</span></td>
                        <td><span id = 1>01</span></td>
                        <td><span id = 2>02</span></td>
                        <td><span id = 3>03</span></td>
                        <td><span id = 4>04</span></td>
                        <td><span id = 5>05</span></td>
                        <td><span id = 6>06</span></td>
                    </tr>

                    <tr>
                        <td><span id = 7>07</span></td>
                        <td><span id = 8>08</span></td>
                        <td><span id = 9>09</span></td>
                        <td><span id = 10>10</span></td>
                        <td><span id = 11>11</span></td>
                        <td><span id = 12>12</span></td>
                        <td><span id = 13>13</span></td>
                    </tr>

                    <tr>
                        <td><span id = 14>14</span></td>
                        <td><span id = 15>15</span></td>
                        <td><span id = 16>16</span></td>
                        <td><span id = 17>17</span></td>
                        <td><span id = 18>18</span></td>
                        <td><span id = 19>19</span></td>
                        <td><span id = 20>20</span></td>
                    </tr>

                    <tr>
                        <td><span id = 21>21</span></td>
                        <td><span id = 22>22</span></td>
                        <td><span id = 23>23</span></td>
                        <td><span id = 24>24</span></td>
                        <td><span id = 25>25</span></td>
                        <td><span id = 26>26</span></td>
                        <td><span id = 27>27</span></td>
                    </tr>

                    <tr>
                        <td><span id = 28>28</span></td>
                        <td><span id = 29>29</span></td>
                        <td><span id = 30>30</span></td>
                        <td><span id = 31>31</span></td>
                        <td><span id = 32>32</span></td>
                        <td><span id = 33>33</span></td>
                        <td><span id = 34>34</span></td>

                    <tr>
                        <td><span id = 35>35</span></td>
                        <td><span id = 36>36</span></td>
                    </tr>

                </table>


                        <br><br>
                        <button onclick = previousMonth()>Previous Month</button>
                        &nbsp;&nbsp;&nbsp;
                        <button onclick = nextMonth()>Next Month</button>

            </div>


        </body>
    </html>
        <script>...
</script>

2 个答案:

答案 0 :(得分:2)

首先,检查文件夹 include 是否与 php 文件位于同一目录中,例如:

\include\jquery-1.11.3.js
\index.php

Javascript标记 src 路径是相对于引用它的html / php文件的位置,或者它可以相对于php网站的根目录,具体取决于您的配置。因此,如果您的文件结构如上所述,但仍未加载,请尝试将 include 上方的目录包含在 src 路径中,例如尝试不同的方式:

<script src="include/jquery-1.11.3.js"></script>
<script src="/include/jquery-1.11.3.js"></script>
<script src="../include/jquery-1.11.3.js"></script>
<script src="[DIRECTORY]/include/jquery-1.11.3.js"></script>

或者,您可以使用jQuery CDN加载jQuery:

<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>

对于其他jQuery版本和相关项目,请参阅:jQuery CDN

答案 1 :(得分:1)

Thanxx好友,我得到了答案。这都是因为没有为jquery lib文件提供读取权限。