Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我的javascript没有';t在外部src页面中工作_Javascript_Jquery_Html_Flash - Fatal编程技术网

我的javascript没有';t在外部src页面中工作

我的javascript没有';t在外部src页面中工作,javascript,jquery,html,flash,Javascript,Jquery,Html,Flash,您好,我正在制作一个flash gallery网站,当我将其放入html中的标记中时,我的javascript可以工作,但当我尝试将其移动到外部.js文件时,它停止工作 HTML JAVASCRIPT $(document).ready ( function(){ var links = [ 'swfs/CP.swf', 'swfs/2cats.swf', /* there is no limit to the array length

您好,我正在制作一个flash gallery网站,当我将其放入html中的
标记中时,我的javascript可以工作,但当我尝试将其移动到外部.js文件时,它停止工作

HTML

JAVASCRIPT

$(document).ready ( function(){
   var links = [
             'swfs/CP.swf',
             'swfs/2cats.swf', /* there is no limit to the array length */
             'swfs/4ChanBrightside.swf',
             'swfs/4chancity.swf',
             'swfs/2spooky4u.swf',
             'swfs/4channer.swf',
             'swfs/5_mile_walk.swf' /* no trailing comma after final item */
            ];
        var displaytext = [
                    'CP',
                   '2cats',
                   'f4ChanBrightside',
                   '4chancity',
                   '2spooky4u',
                   '4channer',
                   '5_mile_walk' /* no trailing comma after final item */
                  ];
        var c = 0
        var flashmovie, test, temp;

        function init() {
            flashmovie = document.getElementById('flashmovie');
            document.getElementById('back').onclick = function () {
                if (c == 0) {
                    c = links.length;
                }
                c--
                displayFiles();
            }

            document.getElementById('next').onclick = function () {
                if (c == links.length - 1) {
                    c = -1;
                }
                c++;
                displayFiles();
            }

            document.getElementById('rand').onclick = function () {
                temp = c;
                while (c == temp) {
                    c = Math.floor(Math.random() * links.length);
                }
                displayFiles();
            }
        }

        function displayFiles() {

            test = links[c].substring(links[c].lastIndexOf('.') + 1, links[c].length);
            document.getElementById('title').innerHTML = displaytext[c];

            flashmovie.innerHTML =
                '<object type="application/x-shockwave-flash" data="' + links[c] + '">' +
                '<param name="movie" value="' + links[c] + '">' +
                '<\/object>';
        }
        window.addEventListener ?
            window.addEventListener('load', init, false) :
            window.attachEvent('onload', init);
});
$(文档).ready(函数(){
变量链接=[
“swfs/CP.swf”,
'swfs/2cats.swf',/*数组长度没有限制*/
“swfs/4ChanBrightside.swf”,
“swfs/4chancity.swf”,
“swfs/2spooky4u.swf”,
“swfs/4channer.swf”,
“swfs/5_mile_walk.swf”/*最后一项后无尾随逗号*/
];
变量displaytext=[
“CP”,
“2卡”,
“Brightside”,
“4汉城”,
“2spooky4u”,
“4汉纳”,
“5英里步行”/*最后一项后无尾随逗号*/
];
var c=0
var、测试、温度;
函数init(){
flashmovie=document.getElementById('flashmovie');
document.getElementById('back')。onclick=function(){
如果(c==0){
c=链接长度;
}
c--
显示文件();
}
document.getElementById('next')。onclick=function(){
if(c==links.length-1){
c=-1;
}
C++;
显示文件();
}
document.getElementById('rand')。onclick=function(){
温度=c;
while(c==temp){
c=Math.floor(Math.random()*links.length);
}
显示文件();
}
}
函数displayFiles(){
test=links[c]。子字符串(links[c]。lastIndexOf('..')+1,links[c]。长度);
document.getElementById('title').innerHTML=displaytext[c];
flashmovie.innerHTML=
'' +
'' +
'';
}
window.addEventListener?
window.addEventListener('load',init,false):
window.attachEvent('onload',init);
});

因此,为了重述代码的工作原理,我想我刚刚搞乱了它的触发方式,比如JQuery$(文档)。准备好了吗?或者我不应该首先使用它?我是javascript新手,所以您的任何建议都会有所帮助

看起来您在包含jQuery之前就已经包含了脚本。您可以尝试将文件的脚本标记移动到正文的底部吗?在包含javascript文件之前,您需要包含jquery库。。。。。。facepalm,我已经做了半个小时了,我不敢相信我忘记了那个事件虽然我是个新手我知道JQuery必须在外部测试之前完成谢谢先生:Dsigh,美好的时光。。。哈哈!发生在我们最好的人身上!问题:这个应该被取下来吗?它对任何人都没有建设性,除了OP.不是仇恨,只是陈述。
body {
    background-color: black;
    margin: 0;
    font-family: verdana, arial, hevetica, sans-serif;
}

#siteText {
    font-size: 24px;
    text-align: center;
    color: white;
    width: 100%;
    margin-top: -10px;
}

#flashmovie {
    width: 100%;
    height: 80%;
    margin-top: -1%;
    float: center;
    position: absolute;
    margin-left: auto;
    margin-right: auto;
}

#flashmovie object {
    width: 100%;
    height: 100%;
    background-color: black;
}

button {
    -moz-border-radius: 2px;
    -webkit-border-radius: 2px;
    width: 80px;
    height: 30px;
}

#buttons {
    width: 50%;
    height: 50px;
    position: relative;
    left: 25%;
    text-align: center;
    background-color: black;
}

#buttoncon {
    top: 90%;
    width: 100%;
    background-color: black;
    position: absolute;
}

#back,
#next {
    float: left;
    cursor: pointer;
    border: none;
}

#next {
    float: right;
}

#title {
    width: 60%;
    margin: auto;
    font-size: 22px;
    color: #600;
    text-align: center;
    color: white;
}

#rand {
    color: black;
    position: relative;
    left: 48%;
    background-color: white;
    border: none;
    cursor: pointer;
    z-index: 1;
    margin-bottom: .5%;
    margin-top: .5%;
}
$(document).ready ( function(){
   var links = [
             'swfs/CP.swf',
             'swfs/2cats.swf', /* there is no limit to the array length */
             'swfs/4ChanBrightside.swf',
             'swfs/4chancity.swf',
             'swfs/2spooky4u.swf',
             'swfs/4channer.swf',
             'swfs/5_mile_walk.swf' /* no trailing comma after final item */
            ];
        var displaytext = [
                    'CP',
                   '2cats',
                   'f4ChanBrightside',
                   '4chancity',
                   '2spooky4u',
                   '4channer',
                   '5_mile_walk' /* no trailing comma after final item */
                  ];
        var c = 0
        var flashmovie, test, temp;

        function init() {
            flashmovie = document.getElementById('flashmovie');
            document.getElementById('back').onclick = function () {
                if (c == 0) {
                    c = links.length;
                }
                c--
                displayFiles();
            }

            document.getElementById('next').onclick = function () {
                if (c == links.length - 1) {
                    c = -1;
                }
                c++;
                displayFiles();
            }

            document.getElementById('rand').onclick = function () {
                temp = c;
                while (c == temp) {
                    c = Math.floor(Math.random() * links.length);
                }
                displayFiles();
            }
        }

        function displayFiles() {

            test = links[c].substring(links[c].lastIndexOf('.') + 1, links[c].length);
            document.getElementById('title').innerHTML = displaytext[c];

            flashmovie.innerHTML =
                '<object type="application/x-shockwave-flash" data="' + links[c] + '">' +
                '<param name="movie" value="' + links[c] + '">' +
                '<\/object>';
        }
        window.addEventListener ?
            window.addEventListener('load', init, false) :
            window.attachEvent('onload', init);
});