Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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数组使脚本短路_Javascript_Arrays - Fatal编程技术网

JavaScript数组使脚本短路

JavaScript数组使脚本短路,javascript,arrays,Javascript,Arrays,我正在用javascript创建一个巨大的数组…它有4层深和许多元素长。我在运行时使用php创建它,这样页面上的所有内容都可以顺利运行,无需进行任何查询 但是,现在,我的数组有一些问题,我的html文件没有看到数组后面列出的javascript函数。通过测试,我缩短了阵列并使其正常工作,但就我的一生而言,我无法理解为什么它会以完整的形式切断其余脚本 如果你能告诉我答案,我将不胜感激 如何使用Firebug来发现问题我对Firebug很陌生 或 B.告诉我问题出在哪里$%^ 我将在php输出下面列

我正在用javascript创建一个巨大的数组…它有4层深和许多元素长。我在运行时使用php创建它,这样页面上的所有内容都可以顺利运行,无需进行任何查询

但是,现在,我的数组有一些问题,我的html文件没有看到数组后面列出的javascript函数。通过测试,我缩短了阵列并使其正常工作,但就我的一生而言,我无法理解为什么它会以完整的形式切断其余脚本

如果你能告诉我答案,我将不胜感激 如何使用Firebug来发现问题我对Firebug很陌生 或 B.告诉我问题出在哪里$%^

我将在php输出下面列出我的整个脚本。出现问题的数组是inventoryNames。我已经检查过了,看问题是否出在妄想症的数量上,但我现在99%肯定是这样。如果我把它评论出来,一切都很好。谢谢

<script type="text/javascript">

var inventoryNames = 
        Array(
            Array(
                Array(
                    Array("AC/DC", "Back in Black", "36", "VG++", "12", ""), 
                    Array("AC/DC", "Back in Black", "37", "VG", "8", "")
                ), 
                Array(
                    Array("AC/DC", "Highway to Hell", "30", "VG++", "10", ""), 
                    Array("AC/DC", "Highway to Hell", "38", "VG", "5", ""), 
                    Array("AC/DC", "Highway to Hell", "35", "NM", "16", ""), 
                    Array("AC/DC", "Highway to Hell", "39", "NM", "14", "")
                )
            ), 
            Array(
                Array(
                    Array("Al Green", "Call Me", "40", "G", "5", ""), 
                    Array("Al Green", "Call Me", "31", "NM", "15", "")
                ), 
                Array(
                    Array("Al Green", "Let's Stay Together", "32", "NM", "12", ""), 
                    Array("Al Green", "Let's Stay Together", "33", "VG++", "10", ""), 
                    Array("Al Green", "Let's Stay Together", "34", "VG", "8", "")
                )
            ), 
            Array(
                Array(
                    Array("B.B. King", "Confessin' the Blues", "45", "VG++", "9", ""), 
                    Array("B.B. King", "Confessin' the Blues", "42", "NM", "35", "")
                ), 
                Array(
                    Array("B.B. King", "Lucille", "43", "VG++", "14", "")
                ), 
                Array(
                    Array("B.B. King", "Singin' the Blues", "41", "NM", "16", "")
                ), 
                Array(
                    Array("B.B. King", "Sings Spirituals", "44", "VG++", "10", "")
                )
            ), 
            Array(
                Array(
                    Array("Bad Company", "Bad Company", "12", "G", "2", ""), 
                    Array("Bad Company", "Bad Company", "13", "M", "38", "1st Edition"), 
                    Array("Bad Company", "Bad Company", "14", "VG+", "8", ""), 
                    Array("Bad Company", "Bad Company", "3", "VG++", "13", "")
                )
            ), 
            Array(
                Array(
                    Array("Bob Dylan", "Another Side of Bob Dylan", "48", "VG++", "20", "")
                ), 
                Array(
                    Array("Bob Dylan", "Blonde on Blonde", "50", "M", "35", "")
                ), 
                Array(
                    Array("Bob Dylan", "Highway 61 Revisited", "49", "NM", "25", "")
                ), 
                Array(
                    Array("Bob Dylan", "The Freewheelin' Bob Dylan", "46", "VG++", "13", "")
                ), 
                Array(
                    Array("Bob Dylan", "The Times They Are A-Changin'", "47", "NM", "25", "")
                )
            ), 
            Array(
                Array(
                    Array("Boston", "Boston", "52", "VG++", "12", ""), 
                    Array("Boston", "Boston", "53", "VG++", "10", ""), 
                    Array("Boston", "Boston", "51", "VG", "7", ""), 
                    Array("Boston", "Boston", "23", "VG", "6", "")
                )
            ), 
            Array(
                Array(
                    Array("Charlie Parker", "Jazz at Massey Hall", "54", "NM", "42", "")
                )
            ), 
            Array(
                Array(
                    Array("Creedence Clearwater Revival", "Green River", "56", "VG++", "13", ""), 
                    Array("Creedence Clearwater Revival", "Green River", "57", "NM", "16", ""), 
                    Array("Creedence Clearwater Revival", "Green River", "55", "VG+", "10", "")
                ), 
                Array(
                    Array("Creedence Clearwater Revival", "Willy and the Poor Boys", "60", "NM", "15", ""), 
                    Array("Creedence Clearwater Revival", "Willy and the Poor Boys", "114", "NM", "16", ""), 
                    Array("Creedence Clearwater Revival", "Willy and the Poor Boys", "58", "G", "5", ""), 
                    Array("Creedence Clearwater Revival", "Willy and the Poor Boys", "59", "VG", "7", "")
                )
            ), 
            Array(
                Array(
                    Array("Dave Brubeck", "Time Out", "61", "NM", "18", ""), 
                    Array("Dave Brubeck", "Time Out", "62", "VG+", "10", "")
                )
            ), 
            Array(
                Array(
                    Array("David Allan Coe", "Longhaired Redneck", "63", "VG+", "8", "")
                ), 
                Array(
                    Array("David Allan Coe", "Rides Again", "64", "VG+", "6", ""), 
                    Array("David Allan Coe", "Rides Again", "65", "NM", "10", "")
                )
            ), 
            Array(
                Array(
                    Array("David Bowie", "Hunky Dory", "18", "NM", "40", "Rare!")
                ), 
                Array(
                    Array("David Bowie", "Ziggy Stardust and the Spiders From Mars", "21", "VG++", "15", "")
                )
            ), 
            Array(
                Array(
                    Array("Earth, Wind & Fire", "Earth, Wind & Fire", "67", "VG+", "10", "")
                ), 
                Array(
                    Array("Earth, Wind & Fire", "That's the Way of the World", "66", "NM", "15", "")
                )
            ), 
            Array(
                Array(
                    Array("Foghat", "Energized", "68", "NM", "10", ""), 
                    Array("Foghat", "Energized", "2", "M", "2", "")
                )
            ), 
            Array(
                Array(
                    Array("George Harrison", "All Things Must Pass", "69", "NM", "35", ""), 
                    Array("George Harrison", "All Things Must Pass", "1", "M", "2", "")
                )
            ), 
            Array(
                Array(
                    Array("Guns N Roses", "Appetite for Destruction", "70", "NM", "20", "")
                )
            ), 
            Array(
                Array(
                    Array("Hank Williams", "Hank Williams Sings", "29", "M", "55", ""), 
                    Array("Hank Williams", "Hank Williams Sings", "71", "NM", "70", "")
                )
            ), 
            Array(
                Array(
                    Array("Herbie Hancock", "Empyrean Isles", "72", "VG++", "10", "")
                ), 
                Array(
                    Array("Herbie Hancock", "Head Hunters", "74", "VG++", "13", "")
                ), 
                Array(
                    Array("Herbie Hancock", "Maiden Voyahe", "73", "VG++", "13", "")
                )
            ), 
            Array(
                Array(
                    Array("Huey Lewis & the News", "Sports", "76", "VG+", "3", ""), 
                    Array("Huey Lewis & the News", "Sports", "77", "VG", "2", ""), 
                    Array("Huey Lewis & the News", "Sports", "75", "NM", "8", "")
                )
            ), 
            Array(
                Array(
                    Array("Its a Beautiful Day", "Its a Beautiful Day", "20", "VG++", "10", "")
                )
            ), 
            Array(
                Array(
                    Array("James Brown", "Prisoner of Love", "78", "VG++", "18", "")
                )
            ), 
            Array(
                Array(
                    Array("Jimi Hendrix", "Are You Experienced", "22", "VG+", "12", "")
                )
            ), 
            Array(
                Array(
                    Array("John Lee Hooker", "John Lee Hooker Plays and Sings the Blues", "81", "VG++", "15", "")
                ), 
                Array(
                    Array("John Lee Hooker", "Travelin'", "80", "VG++", "15", ""), 
                    Array("John Lee Hooker", "Travelin'", "82", "VG+", "15", ""), 
                    Array("John Lee Hooker", "Travelin'", "79", "VG++", "20", "")
                )
            ), 
            Array(
                Array(
                    Array("Mazaak", "Fat Man Suicide", "25", "M", "200", "Includes classics like "Cream Green and Beans" and the title track "Fat Man Suicide"!")
                )
            ), 
            Array(
                Array(
                    Array("Miles Davis", "Bitches Brew", "85", "NM", "30", "")
                ), 
                Array(
                    Array("Miles Davis", "Kind of Blue", "84", "VG+", "15", ""), 
                    Array("Miles Davis", "Kind of Blue", "83", "VG", "10", "")
                ), 
                Array(
                    Array("Miles Davis", "Miles Ahead", "87", "NM", "15", "")
                ), 
                Array(
                    Array("Miles Davis", "Round About Midnight", "86", "NM", "45", "")
                ), 
                Array(
                    Array("Miles Davis", "Star People", "88", "M", "15", "")
                )
            ), 
            Array(
                Array(
                    Array("Motley Crue", "Theatre of Pain", "4", "VG", "5", ""), 
                    Array("Motley Crue", "Theatre of Pain", "16", "VG", "5", "")
                )
            ), 
            Array(
                Array(
                    Array("Muddy Waters", "At Newport", "89", "VG+", "10", "")
                ), 
                Array(
                    Array("Muddy Waters", "Hard Again", "90", "VG++", "15", "")
                )
            ), 
            Array(
                Array(
                    Array("Otis Redding", "In Person at the Whisky a Go Go", "28", "VG++", "20", "")
                ), 
                Array(
                    Array("Otis Redding", "Otis Blue", "92", "VG+", "12", "")
                ), 
                Array(
                    Array("Otis Redding", "The Dock of the Bay", "91", "VG++", "20", "")
                )
            ), 
            Array(
                Array(
                    Array("Ozzy Osbourne", "Bark at the Moon", "95", "VG++", "15", "")
                ), 
                Array(
                    Array("Ozzy Osbourne", "Blizzard of Ozz", "93", "VG++", "10", ""), 
                    Array("Ozzy Osbourne", "Blizzard of Ozz", "94", "VG++", "12", "")
                )
            ), 
            Array(
                Array(
                    Array("Parliament", "Mothership Connection", "96", "VG", "8", "")
                ), 
                Array(
                    Array("Parliament", "Motor Booty Affair", "97", "NM", "12", "")
                )
            ), 
            Array(
                Array(
                    Array("Pink Floyd", "Wish You Were Here", "15", "NM", "17", "")
                )
            ), 
            Array(
                Array(
                    Array("Sly & the Family Stone", "Stand!", "100", "NM", "20", ""), 
                    Array("Sly & the Family Stone", "Stand!", "98", "VG", "8", ""), 
                    Array("Sly & the Family Stone", "Stand!", "99", "VG++", "15", "")
                )
            ), 
            Array(
                Array(
                    Array("Taj Mahal", "Giant Step", "6", "VG+", "13", ""), 
                    Array("Taj Mahal", "Giant Step", "19", "VG+", "10", "")
                )
            ), 
            Array(
                Array(
                    Array("Talking Heads", "Remain in Light", "101", "VG++", "15", ""), 
                    Array("Talking Heads", "Remain in Light", "102", "VG+", "10", ""), 
                    Array("Talking Heads", "Remain in Light", "103", "NM", "20", "")
                ), 
                Array(
                    Array("Talking Heads", "Talking Heads 77", "104", "NM", "25", "")
                )
            ), 
            Array(
                Array(
                    Array("The Allman Brothers Band", "At Fillmore East", "105", "VG++", "15", ""), 
                    Array("The Allman Brothers Band", "At Fillmore East", "106", "VG++", "15", ""), 
                    Array("The Allman Brothers Band", "At Fillmore East", "11", "NM", "16", "")
                ), 
                Array(
                    Array("The Allman Brothers Band", "Eat a Peach", "8", "G", "3", ""), 
                    Array("The Allman Brothers Band", "Eat a Peach", "9", "VG", "8", ""), 
                    Array("The Allman Brothers Band", "Eat a Peach", "10", "M", "20", "")
                )
            ), 
            Array(
                Array(
                    Array("The Beatles", "Rubber Soul", "24", "M", "1.93", "")
                ), 
                Array(
                    Array("The Beatles", "Sgt. Pepper's Lonely Hearts Club Band", "5", "VG+", "15", ""), 
                    Array("The Beatles", "Sgt. Pepper's Lonely Hearts Club Band", "27", "VG++", "20", "")
                )
            ), 
            Array(
                Array(
                    Array("The Mothers of Invention", "Freak Out!", "17", "NM", "20", "")
                )
            ), 
            Array(
                Array(
                    Array("The Rolling Stones", "Exile on Main Street", "107", "NM", "25", "")
                ), 
                Array(
                    Array("The Rolling Stones", "Let It Bleed", "7", "M", "12", "")
                )
            ), 
            Array(
                Array(
                    Array("Thelonious Monk", "Brilliant Corners", "108", "VG++", "30", ""), 
                    Array("Thelonious Monk", "Brilliant Corners", "109", "M", "60", "")
                ), 
                Array(
                    Array("Thelonious Monk", "Monk's Dream", "110", "VG++", "19", ""), 
                    Array("Thelonious Monk", "Monk's Dream", "26", "NM", "35", "")
                )
            ), 
            Array(
                Array(
                    Array("Willie Nelson", "Phases and Stages", "113", "VG++", "12", "")
                ), 
                Array(
                    Array("Willie Nelson", "Red Headed Stranger", "112", "VG++", "11", ""), 
                    Array("Willie Nelson", "Red Headed Stranger", "111", "VG++", "10", "")
                )
            )
        );











var albumNames = Array(Array("Highway to Hell", "Back in Black"), Array("Call Me", "Let's Stay Together"), Array("Singin' the Blues", "Confessin' the Blues", "Sings Spirituals", "Lucille", "Live at the Regal"), Array("Bad Company"), Array("The Freewheelin' Bob Dylan", "The Times They Are A-Changin'", "Another Side of Bob Dylan", "Bringing It All Back Home", "Highway 61 Revisited", "Blonde on Blonde", "John Wesley Harding", "Nashville Skyline", "Self Portrait", "New Morning", "Blood on the Tracks"), Array("Boston"), Array("Jazz at Massey Hall"), Array("Green River", "Cosmos Factory", "Willy and the Poor Boys"), Array("Time Out", "The Dave Brubeck Quartet at Carnegie Hall"), Array("Longhaired Redneck", "Rides Again"), Array("Ziggy Stardust and the Spiders From Mars", "Hunky Dory"), Array("That's the Way of the World", "Earth, Wind & Fire"), Array("Energized"), Array("All Things Must Pass"), Array("Appetite for Destruction"), Array("Hank Williams Sings"), Array("Empyrean Isles", "Maiden Voyahe", "Head Hunters", "Sextant", "Crossings"), Array("Sports", "Picture This"), Array("Its a Beautiful Day"), Array("Prisoner of Love"), Array("Are You Experienced"), Array("Travelin'", "John Lee Hooker Plays and Sings the Blues"), Array("Fat Man Suicide"), Array("Round About Midnight", "Miles Ahead", "Kind of Blue", "Bitches Brew", "Star People"), Array("Theatre of Pain"), Array("At Newport", "Folk Singer", "Brass and the Blues", "Hard Again"), Array("The Dock of the Bay", "Otis Blue", "In Person at the Whisky a Go Go"), Array("Blizzard of Ozz", "Bark at the Moon"), Array("Mothership Connection", "Motor Booty Affair"), Array("Wish You Were Here"), Array("Look What the Cat Dragged In"), Array("The Genius of Ray Charles", "Modern Sounds in Country and Western Music", "The Genius Sings the Blues"), Array("Stand!", "Fresh"), Array("Giant Step", "Taj Mahal", "Happy Just to Be Like I Am", "Music Keeps Me Together"), Array("Remain in Light", "Talking Heads 77", "Speaking in Tongues"), Array("Eat a Peach", "At Fillmore East"), Array("Please Please Me", "A Hard Day's Night", "Help!", "Rubber Soul", "Revolver", "Sgt. Pepper's Lonely Hearts Club Band", "Magical Mystery Tour", "The Beatles (White Album)", "Abbey Road", "Let It Be"), Array("Freak Out!"), Array("Exile on Main Street", "Big Hits (High Tide and Green Grass)", "Let It Bleed"), Array("Brilliant Corners", "Evidence", "Monk's Dream"), Array("Red Headed Stranger", "Yesterday's Wine", "Phases and Stages", "The Sound in Your Mind"));

function byId(id){
      return document.getElementById ?  document.getElementById(id) : document.all[id];
    }
    function populateAlbums(index) {
      var i = byId('albumSelect').options.length;
      for (; i>=0; i--) {
          byId('albumSelect').remove(i);
      }

      var artistAlbums = albumNames[index];
      for (i = 0; i < artistAlbums.length; i++) {
        var option = document.createElement('option');
        option.text = artistAlbums[i];
        option.value = artistAlbums[i];
        try      { byId('albumSelect').add(option, null); } // non-IE
        catch(e) { byId('albumSelect').add(option); } // IE
      }
    }
</script>

其中一个字符串包含双引号:

Array("Mazaak", "Fat Man Suicide", "25", "M", "200", "Includes classics like "Cream Green and Beans" and the title track "Fat Man Suicide"!")
你可以用黑色的斜线来逃脱它们

Array("Mazaak", "Fat Man Suicide", "25", "M", "200", "Includes classics like \"Cream Green and Beans\" and the title track \"Fat Man Suicide\"!")
或者在字符串周围使用单引号

Array("Mazaak", "Fat Man Suicide", "25", "M", "200", 'Includes classics like "Cream Green and Beans" and the title track "Fat Man Suicide"!')
ArrayMazaak,《胖子自杀》,25岁,男,200岁,包括奶油绿和豆子等经典曲目和标题曲《胖子自杀》


您没有在字符串中转义文本,因此代码正在中断。进入php并用\

替换,您并没有逃逸正在JS代码中打印的字符串

当JS中出现语法错误时,脚本的其余部分甚至不会被计算,因此您永远不会找到语法错误以下的任何内容

三项建议:

在打印字符串之前使用。 使用紧凑语法创建数组: 例如:

var inventoryNames =
    [
        [
            [
                ["AC/DC", "Back in Black", "36", "VG++", "12", ""], 
                ["AC/DC", "Back in Black", "37", "VG", "8", ""]
            ), 
            [
                ["AC/DC", "Highway to Hell", "30", "VG++", "10", ""], 
                ["AC/DC", "Highway to Hell", "38", "VG", "5", ""], 
                ["AC/DC", "Highway to Hell", "35", "NM", "16", ""], 
                ["AC/DC", "Highway to Hell", "39", "NM", "14", ""]
            ]
        ], 
使用类似的方式发布与JS/HTML相关的问题。
祝你好运

松开数组,只需使用方括号var arr=[[1,2,3]、[4,5,6]、[7,8,9];我不知道你的方案,但是如果你要在每个页面请求发送,你可能会浪费很多带宽。你可能想考虑使用JavaScript数组常量符号:[a,b,c],而不是数组构造器。还有一个额外的原因来领导其他人的建议来代替数组[]:安全性。无法保证数组构造函数没有被邪恶的人覆盖。数组文字语法可防止在这种情况下泄漏信息。