Uncaught ReferenceError: jQuery is not defined
本问题已经有最佳答案,请猛点这里访问。
我在我的站点上实现了一些javascript,但我一直收到以下错误消息:
Uncaught ReferenceError: jQuery is not defined
和
Uncaught SyntaxError: Unexpected token <
这是我在header.php中使用的javascript:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | <script type="text/javascript" src="/test/wp-content/themes/child/script/jquery.jcarousel.min.js"> <script type="text/javascript" src="/test/wp-content/themes/child/script/jquery.scrollTo.js"> <script type="text/javascript" src="/test/wp-content/themes/child/script/jquery.backgroundPosition.js"> <script type="text/javascript" src="/test/wp-content/themes/child/script/scripts.js"> <script type="text/javascript" src="/test/wp-content/themes/child/script/jquery.cycle.lite.js"> <script type="text/javascript" src="/test/wp-content/themes/child/script/jquery.accordian.js"> <script type="text/javascript"> jQuery(document).ready(function () { jQuery('#contentGallery').cycle({ fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc... }); }); </head> <body <?php body_class(); ?>> <header id="branding" role="banner"> <hgroup> <h1 id="site-title"><span>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></span> <h2 id="site-description"><?php bloginfo( 'description' ); ?> </hgroup> <?php // Check to see if the header image has been removed $header_image = get_header_image(); if ( ! empty( $header_image ) ) : ?> "> <?php // The header image // Check if this is a post or page, if it has a thumbnail, and if it's a big one if ( is_singular() && has_post_thumbnail( $post->ID ) && ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( HEADER_IMAGE_WIDTH, HEADER_IMAGE_WIDTH ) ) ) && $image[1] >= HEADER_IMAGE_WIDTH ) : // Houston, we have a new header image! echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' ); else : ?> <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" /> <?php endif; // end check for featured image or standard header ?> <?php endif; // end check for removed header image ?> <nav id="access" role="navigation"> <ul> <li class="end"> </li> <li> </li> <li> </li> <li> </li> </ul> <img src="Images/Gallery/london.jpg" width="1200" height="550" alt="London" /> <img src="Images/Gallery/singapore.jpg" style="display: none;" width="1200" height="550" alt="Singapore" /> <img src="Images/Gallery/geneva.jpg" style="display: none;" width="1200" height="550" alt="Geneva" /> <span class="homeHeaderText">GMR</span> <p> very long text 1 </p> <span class="headerText">About Us</span> <p> Insert text here. </p> <table border="0" cellpadding="0" cellspacing="0" class="linkTable"> <tr> <td valign="middle" height="100%"> The Art </td> <td valign="middle" height="100%"> The Science </td> </tr> </table> <span class="headerText">The Art</span> Sensitivity <p> very long text 2 </p> Creativity <p> very long text 3 </p> Intuition <p> very long text 4 </p> Judgment <p> very long text 5 </p> The Science <span class="headerText">The Science</span> Methodology <p> very long text 6 </p> Research <p> very long text 7 </p> Team Approach <p> very long text 8 </p> Sharing Information <p> very long text 9 </p> The Art <span class="headerText">Expertise</span> Expertise <p> very long text 10 </p> Business Context <p> very long text 11 </p> Cultural Context <p> very long text 12 </p> Candidate Context <p> very long text 13 </p> Financial Context <p> very long text 14 </p> Service Context <p> very long text 15 </p> <span class="headerText">Contact</span> Tel: +44(0)1234 567 890 Email: info@info <h3 class="assistive-text"><?php _e( 'Main menu', 'twentyeleven' ); ?> <?php /* Allow screen readers / text browsers to skip the navigation menu and get right to the good stuff. */ ?> "><?php _e( 'Skip to primary content', 'twentyeleven' ); ?> "><?php _e( 'Skip to secondary content', 'twentyeleven' ); ?> <?php /* Our navigation menu. If one isn't filled out, wp_nav_menu falls back to wp_page_menu. The menu assiged to the primary position is the one used. If none is assigned, the menu with the lowest ID is used. */ ?> </nav><!-- #access --> </header><!-- #branding --> |
这是我在footer.php中使用的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <ul> <li class="start">Home </li> <li> About Us </li> <li> Approach </li> <li> Expertise </li> </ul> |
jquery需要是导入的第一个脚本。页面上的第一个脚本
1 | <script type="text/javascript" src="/test/wp-content/themes/child/script/jquery.jcarousel.min.js"> |
似乎是一个jquery插件,因为jquery还没有加载到页面上,所以很可能会产生错误。
你需要把它放在wp_head()后面。因为这会加载您的jquery,您需要先加载jquery,然后加载JS。
在我的例子中,发生错误是因为我使用了错误的jquery版本。
1 | <script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"> |
我把它改成:
1 | <script src="http://code.jquery.com/jquery-1.11.3.min.js"> |
设置此jquery min js
1 | script src="http://code.jquery.com/jquery-1.10.1.min.js" |
在wp admin/admin-header.php中
首先,您似乎并没有将jquery本身包含在头中,而是只包含了一堆插件。对于"<"错误,不看到生成的HTML就无法判断。