Javascript JQuery出现错误-但我没有';我不知道如何解决这个问题

Javascript JQuery出现错误-但我没有';我不知道如何解决这个问题,javascript,jquery,Javascript,Jquery,为我们的学生广播电台建立一个网站——这段代码在Firefox中有效,但由于某些原因在Chrome中不起作用。 我读过以前的文章,他们也有类似的错误,这是因为JavaScript没有放在页面的顶部-但是,在将所有JavaScript移到页眉中之后,我不理解为什么页面仍然有许多错误(在Chrome调试控制台中运行) 试试这个,也许是工作: $(document).ready(function(){ $('#ca-container').contentcarousel(); });

为我们的学生广播电台建立一个网站——这段代码在Firefox中有效,但由于某些原因在Chrome中不起作用。 我读过以前的文章,他们也有类似的错误,这是因为JavaScript没有放在页面的顶部-但是,在将所有JavaScript移到页眉中之后,我不理解为什么页面仍然有许多错误(在Chrome调试控制台中运行)


试试这个,也许是工作:

$(document).ready(function(){
   $('#ca-container').contentcarousel();
});     
完全加载窗口后调用
contentcarousel()

您还需要在另一个js库之前包含jquery:

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

您提到的问题在jQuery代码中。我看到的唯一jQuery调用是:

$('#ca-container').contentcarousel();
如果此操作无法正常工作,很可能是因为您需要等待文档加载后才能执行:

$(document).on('ready', function() {
    $('#ca-container').contentcarousel();
});
否则执行jQuery代码时,
ca容器
元素不存在


更新:


您还忘记将jQuery库包含在

中。将旋转木马jQuery代码从body移动到head元素,并在document.ready事件中调用它。还包括对jQuery库本身的引用:

<head>
<script src="http://code.jquery.com/jquery-latest.min.js"
    type="text/javascript"></script>
 <style type="text/css"> #mainContent {margin-top:-16%;} </style>
<link href="css/presenters.css" rel="stylesheet">
<!-- the jScrollPane script -->
        <script type="text/javascript" src="js/jquery.mousewheel.js"></script>

            <script type="text/javascript" src="js/jquery.contentcarousel.js"></script>
        <script type="text/javascript">
                    $(document).ready(function(){
                        $('#ca-container').contentcarousel();
                    });
        </script>       
        <script type="text/javascript">
            var aImages = [ "images/banner/banner1.jpg" , "images/banner/banner2.jpg", "images/banner/banner3.jpg", "images/banner/banner4.jpg",];
            var oImage = null;
            var iIdx = 0;

    function play(){
    try{
            //look only once in DOM and cache it
            if(oImage===null){
            oImage = window.document.getElementById("imgHolder");
            }
            oImage.src = aImages[(++iIdx)%(aImages.length)];
        setTimeout('play()',10000);
        }catch(oEx){
        //some error handling here
        }
        }
        </script>   



</head>
    <body onload="play()">
<section id="content">
    <section id="headerArea">
        <section id="mainHeader">
            <section id="leftHeader">
                <a href="index.php"> <img src="images/clicklogowb.png" height="200px" width="330"> </a>
            </section>          
            <section id="rightHeader">
                <section id="rightTop">
                    <img src="images/header.png">
                </section>
        </section>

<section id="mainContent">
        <section id="blocks">
                <section id="topBlocks">

  <br>
    <h5>Presenters</h5>
            <div id="ca-container" class="ca-container">
                <div class="ca-wrapper">
                    <div class="ca-item ca-item-1">
                        <div class="ca-item-main">
                            <div class="ca-icon"></div>
                            <h3>Priscilla</h3>
                            <h4>
                                <span class="ca-quote">&ldquo;</span>
                                <span>The greatness of a nation and its moral progress can be judged by the way in which its animals are treated.</span>
                            </h4>
                                <a href="#" class="ca-more">more...</a>
                        </div>
                        <div class="ca-content-wrapper">
                            <div class="ca-content">

                                <a href="#" class="ca-close">close</a>
                                <div class="ca-content-text">
                                    <p>I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents. I should be incapable of drawing a single stroke at the present moment; and yet I feel that I never was a greater artist than now.</p>
                                    <p>When, while the lovely valley teems with vapour around me, and the meridian sun strikes the upper surface of the impenetrable foliage of my trees, and but a few stray gleams steal into the inner sanctuary, I throw myself down among the tall grass by the trickling stream;</p>
                                    <p>She packed her seven versalia, put her initial into the belt and made herself on the way.</p>
                                </div>
                                                            </div>
                        </div>
                    </div>
                    <div class="ca-item ca-item-2">
                        <div class="ca-item-main">
                            <div class="ca-icon"></div>
                            <h3>Lucy</h3>
                            <h4>
                                <span class="ca-quote">&ldquo;</span>
                                <span>I hold that the more helpless a creature, the more entitled it is to protection by man from the cruelty of man.</span>
                            </h4>
                                <a href="#" class="ca-more">more...</a>
                        </div>
                        <div class="ca-content-wrapper">
                            <div class="ca-content">
                                                            <a href="#" class="ca-close">close</a>
                                <div class="ca-content-text">
                                    <p>I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents. I should be incapable of drawing a single stroke at the present moment; and yet I feel that I never was a greater artist than now.</p>
                                    <p>When, while the lovely valley teems with vapour around me, and the meridian sun strikes the upper surface of the impenetrable foliage of my trees, and but a few stray gleams steal into the inner sanctuary, I throw myself down among the tall grass by the trickling stream;</p>
                                    <p>She packed her seven versalia, put her initial into the belt and made herself on the way.</p>
                                </div>

                            </div>
                        </div>
                    </div>
                    <div class="ca-item ca-item-3">
                        <div class="ca-item-main">
                            <div class="ca-icon"></div>
                            <h3>Nat</h3>
                            <h4>
                                <span class="ca-quote">&ldquo;</span>
                                <span>I feel that spiritual progress does demand at some stage that we should cease to kill our fellow creatures for the satisfaction of our bodily wants.</span>
                            </h4>
                                <a href="#" class="ca-more">more...</a>
                        </div>
                        <div class="ca-content-wrapper">
                            <div class="ca-content">
                                                            <a href="#" class="ca-close">close</a>
                                <div class="ca-content-text">
                                    <p>I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents. I should be incapable of drawing a single stroke at the present moment; and yet I feel that I never was a greater artist than now.</p>
                                    <p>When, while the lovely valley teems with vapour around me, and the meridian sun strikes the upper surface of the impenetrable foliage of my trees, and but a few stray gleams steal into the inner sanctuary, I throw myself down among the tall grass by the trickling stream;</p>
                                    <p>She packed her seven versalia, put her initial into the belt and made herself on the way.</p>
                                </div>
                                                    </div>
                        </div>
                    </div>
                    <div class="ca-item ca-item-4">
                        <div class="ca-item-main">
                            <div class="ca-icon"></div>
                            <h3>Katya</h3>
                            <h4>
                                <span class="ca-quote">&ldquo;</span>
                                <span>A man is but the product of his thoughts what he thinks, he becomes.</span>
                            </h4>
                                <a href="#" class="ca-more">more...</a>
                        </div>
                        <div class="ca-content-wrapper">
                            <div class="ca-content">
                                                            <a href="#" class="ca-close">close</a>
                                <div class="ca-content-text">
                                    <p>I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents. I should be incapable of drawing a single stroke at the present moment; and yet I feel that I never was a greater artist than now.</p>
                                    <p>When, while the lovely valley teems with vapour around me, and the meridian sun strikes the upper surface of the impenetrable foliage of my trees, and but a few stray gleams steal into the inner sanctuary, I throw myself down among the tall grass by the trickling stream;</p>
                                    <p>She packed her seven versalia, put her initial into the belt and made herself on the way.</p>
                                </div>

                            </div>
                        </div>
                    </div>
                    <div class="ca-item ca-item-5">
                        <div class="ca-item-main">
                            <div class="ca-icon"></div>
                            <h3>Rebecca</h3>
                            <h4>
                                <span class="ca-quote">&ldquo;</span>
                                <span>A weak man is just by accident. A strong but non-violent man is unjust by accident.</span>
                            </h4>
                                <a href="#" class="ca-more">more...</a>
                        </div>
                        <div class="ca-content-wrapper">
                            <div class="ca-content">
                                                                <a href="#" class="ca-close">close</a>
                                <div class="ca-content-text">
                                    <p>I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents. I should be incapable of drawing a single stroke at the present moment; and yet I feel that I never was a greater artist than now.</p>
                                    <p>When, while the lovely valley teems with vapour around me, and the meridian sun strikes the upper surface of the impenetrable foliage of my trees, and but a few stray gleams steal into the inner sanctuary, I throw myself down among the tall grass by the trickling stream;</p>
                                    <p>She packed her seven versalia, put her initial into the belt and made herself on the way.</p>
                                </div>

                            </div>
                        </div>
                    </div>
                    <div class="ca-item ca-item-6">
                        <div class="ca-item-main">
                            <div class="ca-icon"></div>
                            <h3>Dan</h3>
                            <h4>
                                <span class="ca-quote">&ldquo;</span>
                                <span>An error does not become truth by reason of multiplied propagation, nor does truth become error because nobody sees it.</span>
                            </h4>
                                <a href="#" class="ca-more">more...</a>
                        </div>
                        <div class="ca-content-wrapper">
                            <div class="ca-content">

                                <a href="#" class="ca-close">close</a>
                                <div class="ca-content-text">
                                    <p>I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents. I should be incapable of drawing a single stroke at the present moment; and yet I feel that I never was a greater artist than now.</p>
                   ---------------- TRUNCATED

#主要内容{利润率最高:-16%;}
$(文档).ready(函数(){
$(“#ca容器”).contentcarousel();
});
var aImages=[“images/banner/banner1.jpg”、“images/banner/banner2.jpg”、“images/banner/banner3.jpg”、“images/banner/banner4.jpg”,];
var oImage=null;
var iIdx=0;
函数播放(){
试一试{
//在DOM中只查看一次并缓存它
如果(oImage==null){
oImage=window.document.getElementById(“imgHolder”);
}
oImage.src=aImages[(++iIdx)%(aImages.length)];
setTimeout('play()',10000);
}渔获物(oEx){
//这里有一些错误处理
}
}

演讲者 普里西拉 &ldquo; 一个国家的伟大和道德进步可以通过对待动物的方式来判断。 我是如此的快乐,我亲爱的朋友,我是如此的专注于纯粹宁静存在的美妙感觉,以至于我忽视了我的才能。我现在一笔也画不出来;但我觉得我从来没有像现在这样成为一个伟大的艺术家

当可爱的山谷里弥漫着我周围的水汽,午后的太阳照射在我那无法穿透的树叶的上表面,只有几缕零星的微光潜入了我内心的圣殿时,我扑倒在涓涓细流旁的高草中

她把她的七个versalia打包,把她的首字母放在腰带上,然后上路了

露西 &ldquo; 我认为,一个生物越是无助,它就越有权受到人类的保护,免受人类的残忍。 我是如此的快乐,我亲爱的朋友,我是如此的专注于纯粹宁静存在的美妙感觉,以至于我忽视了我的才能。我现在一笔也画不出来;但我觉得我从来没有像现在这样成为一个伟大的艺术家

当可爱的山谷里弥漫着我周围的水汽,午后的太阳照射在我那无法穿透的树叶的上表面,只有几缕零星的微光潜入了我内心的圣殿时,我扑倒在涓涓细流旁的高草中

她把她的七个versalia打包,把她的首字母放在腰带上,然后上路了

纳特 &ldquo; 我觉得精神上的进步确实要求在某个阶段,我们应该停止为了满足我们身体上的需要而杀害我们的同类。 我是如此的快乐,我亲爱的朋友,我是如此的专注于纯粹宁静存在的美妙感觉,以至于我忽视了我的才能。我现在一笔也画不出来;但我觉得
$(document).on('ready', function() {
    $('#ca-container').contentcarousel();
});
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"
    type="text/javascript"></script>
 <style type="text/css"> #mainContent {margin-top:-16%;} </style>
<link href="css/presenters.css" rel="stylesheet">
<!-- the jScrollPane script -->
        <script type="text/javascript" src="js/jquery.mousewheel.js"></script>

            <script type="text/javascript" src="js/jquery.contentcarousel.js"></script>
        <script type="text/javascript">
                    $(document).ready(function(){
                        $('#ca-container').contentcarousel();
                    });
        </script>       
        <script type="text/javascript">
            var aImages = [ "images/banner/banner1.jpg" , "images/banner/banner2.jpg", "images/banner/banner3.jpg", "images/banner/banner4.jpg",];
            var oImage = null;
            var iIdx = 0;

    function play(){
    try{
            //look only once in DOM and cache it
            if(oImage===null){
            oImage = window.document.getElementById("imgHolder");
            }
            oImage.src = aImages[(++iIdx)%(aImages.length)];
        setTimeout('play()',10000);
        }catch(oEx){
        //some error handling here
        }
        }
        </script>   



</head>
    <body onload="play()">
<section id="content">
    <section id="headerArea">
        <section id="mainHeader">
            <section id="leftHeader">
                <a href="index.php"> <img src="images/clicklogowb.png" height="200px" width="330"> </a>
            </section>          
            <section id="rightHeader">
                <section id="rightTop">
                    <img src="images/header.png">
                </section>
        </section>

<section id="mainContent">
        <section id="blocks">
                <section id="topBlocks">

  <br>
    <h5>Presenters</h5>
            <div id="ca-container" class="ca-container">
                <div class="ca-wrapper">
                    <div class="ca-item ca-item-1">
                        <div class="ca-item-main">
                            <div class="ca-icon"></div>
                            <h3>Priscilla</h3>
                            <h4>
                                <span class="ca-quote">&ldquo;</span>
                                <span>The greatness of a nation and its moral progress can be judged by the way in which its animals are treated.</span>
                            </h4>
                                <a href="#" class="ca-more">more...</a>
                        </div>
                        <div class="ca-content-wrapper">
                            <div class="ca-content">

                                <a href="#" class="ca-close">close</a>
                                <div class="ca-content-text">
                                    <p>I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents. I should be incapable of drawing a single stroke at the present moment; and yet I feel that I never was a greater artist than now.</p>
                                    <p>When, while the lovely valley teems with vapour around me, and the meridian sun strikes the upper surface of the impenetrable foliage of my trees, and but a few stray gleams steal into the inner sanctuary, I throw myself down among the tall grass by the trickling stream;</p>
                                    <p>She packed her seven versalia, put her initial into the belt and made herself on the way.</p>
                                </div>
                                                            </div>
                        </div>
                    </div>
                    <div class="ca-item ca-item-2">
                        <div class="ca-item-main">
                            <div class="ca-icon"></div>
                            <h3>Lucy</h3>
                            <h4>
                                <span class="ca-quote">&ldquo;</span>
                                <span>I hold that the more helpless a creature, the more entitled it is to protection by man from the cruelty of man.</span>
                            </h4>
                                <a href="#" class="ca-more">more...</a>
                        </div>
                        <div class="ca-content-wrapper">
                            <div class="ca-content">
                                                            <a href="#" class="ca-close">close</a>
                                <div class="ca-content-text">
                                    <p>I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents. I should be incapable of drawing a single stroke at the present moment; and yet I feel that I never was a greater artist than now.</p>
                                    <p>When, while the lovely valley teems with vapour around me, and the meridian sun strikes the upper surface of the impenetrable foliage of my trees, and but a few stray gleams steal into the inner sanctuary, I throw myself down among the tall grass by the trickling stream;</p>
                                    <p>She packed her seven versalia, put her initial into the belt and made herself on the way.</p>
                                </div>

                            </div>
                        </div>
                    </div>
                    <div class="ca-item ca-item-3">
                        <div class="ca-item-main">
                            <div class="ca-icon"></div>
                            <h3>Nat</h3>
                            <h4>
                                <span class="ca-quote">&ldquo;</span>
                                <span>I feel that spiritual progress does demand at some stage that we should cease to kill our fellow creatures for the satisfaction of our bodily wants.</span>
                            </h4>
                                <a href="#" class="ca-more">more...</a>
                        </div>
                        <div class="ca-content-wrapper">
                            <div class="ca-content">
                                                            <a href="#" class="ca-close">close</a>
                                <div class="ca-content-text">
                                    <p>I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents. I should be incapable of drawing a single stroke at the present moment; and yet I feel that I never was a greater artist than now.</p>
                                    <p>When, while the lovely valley teems with vapour around me, and the meridian sun strikes the upper surface of the impenetrable foliage of my trees, and but a few stray gleams steal into the inner sanctuary, I throw myself down among the tall grass by the trickling stream;</p>
                                    <p>She packed her seven versalia, put her initial into the belt and made herself on the way.</p>
                                </div>
                                                    </div>
                        </div>
                    </div>
                    <div class="ca-item ca-item-4">
                        <div class="ca-item-main">
                            <div class="ca-icon"></div>
                            <h3>Katya</h3>
                            <h4>
                                <span class="ca-quote">&ldquo;</span>
                                <span>A man is but the product of his thoughts what he thinks, he becomes.</span>
                            </h4>
                                <a href="#" class="ca-more">more...</a>
                        </div>
                        <div class="ca-content-wrapper">
                            <div class="ca-content">
                                                            <a href="#" class="ca-close">close</a>
                                <div class="ca-content-text">
                                    <p>I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents. I should be incapable of drawing a single stroke at the present moment; and yet I feel that I never was a greater artist than now.</p>
                                    <p>When, while the lovely valley teems with vapour around me, and the meridian sun strikes the upper surface of the impenetrable foliage of my trees, and but a few stray gleams steal into the inner sanctuary, I throw myself down among the tall grass by the trickling stream;</p>
                                    <p>She packed her seven versalia, put her initial into the belt and made herself on the way.</p>
                                </div>

                            </div>
                        </div>
                    </div>
                    <div class="ca-item ca-item-5">
                        <div class="ca-item-main">
                            <div class="ca-icon"></div>
                            <h3>Rebecca</h3>
                            <h4>
                                <span class="ca-quote">&ldquo;</span>
                                <span>A weak man is just by accident. A strong but non-violent man is unjust by accident.</span>
                            </h4>
                                <a href="#" class="ca-more">more...</a>
                        </div>
                        <div class="ca-content-wrapper">
                            <div class="ca-content">
                                                                <a href="#" class="ca-close">close</a>
                                <div class="ca-content-text">
                                    <p>I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents. I should be incapable of drawing a single stroke at the present moment; and yet I feel that I never was a greater artist than now.</p>
                                    <p>When, while the lovely valley teems with vapour around me, and the meridian sun strikes the upper surface of the impenetrable foliage of my trees, and but a few stray gleams steal into the inner sanctuary, I throw myself down among the tall grass by the trickling stream;</p>
                                    <p>She packed her seven versalia, put her initial into the belt and made herself on the way.</p>
                                </div>

                            </div>
                        </div>
                    </div>
                    <div class="ca-item ca-item-6">
                        <div class="ca-item-main">
                            <div class="ca-icon"></div>
                            <h3>Dan</h3>
                            <h4>
                                <span class="ca-quote">&ldquo;</span>
                                <span>An error does not become truth by reason of multiplied propagation, nor does truth become error because nobody sees it.</span>
                            </h4>
                                <a href="#" class="ca-more">more...</a>
                        </div>
                        <div class="ca-content-wrapper">
                            <div class="ca-content">

                                <a href="#" class="ca-close">close</a>
                                <div class="ca-content-text">
                                    <p>I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents. I should be incapable of drawing a single stroke at the present moment; and yet I feel that I never was a greater artist than now.</p>
                   ---------------- TRUNCATED
<script type="text/javascript" src="js/jquery.mousewheel.js"></script>      
<script type="text/javascript" src="js/jquery.contentcarousel.js"></script>