简体   繁体   English

Javascript问题,flexslider脚本未加载

[英]Javascript Issue, flexslider script not loading

I recently had to rebuild a website from web archive. 我最近不得不从Web存档重建网站。 The client web dev disapeared.. Anyways I got everyting working again except the javascript that runs the flexslider. 客户端Web开发人员消失了。无论如何,除了运行flexslider的javascript之外,我都重新开始了工作。

go to gervee.com to see the side, if you click the arrows it does nothing. 请访问gervee.com来查看侧面,如果单击箭头则无济于事。 The console shows this error: 控制台显示此错误:

Uncaught ReferenceError: jQuery is not defined on line 12 未捕获的ReferenceError:第12行未定义jQuery

here is the code 这是代码

jQuery('.flexslider').flexslider({ animation: "slide" }); jQuery('。flexslider')。flexslider({animation:“ slide”});

yet glancing at the javascript files, it appears that there is flexslider code. 瞥了一眼javascript文件,似乎有flexslider代码。 However Not sure what to do next. 但是不知道下一步该怎么做。

Try moveing that line to after the rest of your scripts and then surounding the code with 尝试将该行移至其余脚本之后,然后使用

$(document).ready(function() {
    // code here
}); 

Here is what gervee.com has currently: 这是gervee.com当前拥有的内容:

<script type="text/javascript"> jQuery('.flexslider').flexslider({ animation: "slide" });</script>
<script type="text/javascript"> document.cookie = 'adaptive_image=' + Math.max(screen.width, screen.height) + '; path=/'; </script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript"> window.jQuery || document.write("<script src='/sites/all/modules/jquery_update/replace/jquery/1.5/jquery.min.js'>\x3C/script>") </script>

It is trying to use jQuery before it is loaded. 它试图在加载之前使用jQuery。 Try changing it to this (move flexslider to after jQuery is loaded): 尝试将其更改为此(在加载jQuery之后将flexslider移至):

<script type="text/javascript"> document.cookie = 'adaptive_image=' + Math.max(screen.width, screen.height) + '; path=/'; </script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript"> window.jQuery || document.write("<script src='/sites/all/modules/jquery_update/replace/jquery/1.5/jquery.min.js'>\x3C/script>") </script>
<script type="text/javascript"> jQuery('.flexslider').flexslider({ animation: "slide" });</script>

Also, I know you are just trying to get this back up and working for them, but ideally you would not want to load scripts in <head> . 另外,我知道您只是想将其备份并为它们工作,但是理想情况下,您不想在<head>加载脚本。 It would be better to reference them at the bottom of <body> and also to use $(function() { ... }) to execute any javascript on document.ready instead of inline (as LukasGuptaLeary mentioned in his answer). 最好在<body>的底部引用它们,并使用$(function() { ... })在document.ready上执行任何javascript而不是内联(如LukasGuptaLeary在他的回答中提到的)。 That makes the page load faster and helps prevent issues with things being used before they are loaded. 这样可以加快页面加载速度,并有助于防止在加载之前使用中的问题。 Just felt the need to mention this. 只是觉得有必要提一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM