Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.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 - Fatal编程技术网

Javascript 无法读取数组

Javascript 无法读取数组,javascript,Javascript,嘿,我试图制作一个阵列,读取所有内容,然后用用户提供的内容进行检查,但情况是这样的,当我选择“ATI Radeon HD 2600 Overview”时,它可以工作,但当我选择“ATI Radeon X1950 Series”或之后的任何内容时,它不工作,它只会挂起整个系统。下面是代码 function setValue() { myVariable = document.forms["myform"]["gname"].value; myVariable2 = document

嘿,我试图制作一个阵列,读取所有内容,然后用用户提供的内容进行检查,但情况是这样的,当我选择“ATI Radeon HD 2600 Overview”时,它可以工作,但当我选择“ATI Radeon X1950 Series”或之后的任何内容时,它不工作,它只会挂起整个系统。下面是代码

function setValue() {
    myVariable = document.forms["myform"]["gname"].value;
    myVariable2 = document.forms["myform"]["gpc"].value;
    myVariable3 = document.forms["myform"]["procesor"].value;
    myVariable4 = document.forms["myform"]["ram"].value;
    myVariable5 = document.forms["myform"]["os"].value;
    var gname = ["Prince of Persia: The Forgotten Sands", "Gears of War", "yes"];
    var gpc = ["Radeon HD 2600 Pro", "GeForce 8600 GTS 512MB", "ATI Radeon 5000 Series", "ATI Radeon 4000 Series", "ATI Radeon 3000 Series", "ATI Radeon HD 2900 Overview", "ATI Radeon HD 2600 Overview", "ATI Radeon X1950 Series", "ATI Radeon X1800 Series", "ATI Radeon X1650 Series"];
    var procesor = ["Core 2 Duo E4500 2.2GHz", "Athlon 64 X2 Dual Core 4400+", "yes"];
    var ram = ["3 GB", "2 GB", "1 GB"];
    var os = ["Windows Xp", "Windows 7", "Windows Vista", "Windows 8"];
    var canRun = false;
    for (i = 0; i < gname.length; i++)
    if (myVariable === gname[i]) //changed from 0 to i here
    {
        for (i = 0; i < gpc.length; i++) {
            if (myVariable2 === gpc[i]) //changed from 0 to i here
            {
                for (i = 0; i < procesor.length; i++) {
                    if (myVariable3 === procesor[i]) //changed from 0 to i here
                    {
                        for (i = 0; i < ram.length; i++) {
                            if (myVariable4 === ram[i]) //changed from 0 to i here
                            {
                                for (i = 0; i < os.length; i++) {
                                    if (myVariable5 === os[i]) //changed from 0 to i here
                                    {
                                        //but when my input is in the array it can run
                                        canRun = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    if (canRun) {
        alert("yes this game can run");
    } else {
        alert("No, This game cannot run");
    }
};
函数setValue(){
myVariable=document.forms[“myform”][“gname”].value;
myVariable2=document.forms[“myform”][“gpc”].value;
myVariable3=document.forms[“myform”][“procesor”].value;
myVariable4=document.forms[“myform”][“ram”].value;
myVariable5=document.forms[“myform”][“os”].value;
var gname=[“波斯王子:被遗忘的沙子”,“战争的齿轮”,“是的”];
var gpc=[“Radeon HD 2600 Pro”、“GeForce 8600 GTS 512MB”、“ATI Radeon 5000系列”、“ATI Radeon 4000系列”、“ATI Radeon 3000系列”、“ATI Radeon HD 2900概述”、“ATI Radeon HD 2600概述”、“ATI Radeon X1950系列”、“ATI Radeon X1800系列”、“ATI Radeon X1650系列”];
var procesor=[“核心2双E45002.2GHz”,“Athlon 64 X2双核4400+”,“是”];
var ram=[“3 GB”、“2 GB”、“1 GB”];
var os=[“Windows Xp”、“Windows 7”、“Windows Vista”、“Windows 8”];
var canRun=false;
对于(i=0;i
这是因为循环变量
i
,在每个
for
循环中,您需要使用不同的循环变量,如
i、j、k、l
等。。。差不多

function setValue() {
    myVariable = document.forms["myform"]["gname"].value;
    myVariable2 = document.forms["myform"]["gpc"].value;
    myVariable3 = document.forms["myform"]["procesor"].value;
    myVariable4 = document.forms["myform"]["ram"].value;
    myVariable5 = document.forms["myform"]["os"].value;
    var gname = ["Prince of Persia: The Forgotten Sands", "Gears of War", "yes"];
    var gpc = ["Radeon HD 2600 Pro", "GeForce 8600 GTS 512MB", "ATI Radeon 5000 Series", "ATI Radeon 4000 Series", "ATI Radeon 3000 Series", "ATI Radeon HD 2900 Overview", "ATI Radeon HD 2600 Overview", "ATI Radeon X1950 Series", "ATI Radeon X1800 Series", "ATI Radeon X1650 Series"];
    var procesor = ["Core 2 Duo E4500 2.2GHz", "Athlon 64 X2 Dual Core 4400+", "yes"];
    var ram = ["3 GB", "2 GB", "1 GB"];
    var os = ["Windows Xp", "Windows 7", "Windows Vista", "Windows 8"];
    var canRun = false;
    for (i = 0; i < gname.length; i++)
    if (myVariable === gname[i]) //changed from 0 to i here
    {
        for (j = 0; j < gpc.length; j++) {
            if (myVariable2 === gpc[j]) //changed from 0 to i here
            {
                for (k = 0; k < procesor.length; k++) {
                    if (myVariable3 === procesor[k]) //changed from 0 to i here
                    {
                        for (l = 0; l < ram.length; l++) {
                            if (myVariable4 === ram[l]) //changed from 0 to i here
                            {
                                for (m = 0; m < os.length; m++) {
                                    if (myVariable5 === os[m]) //changed from 0 to i here
                                    {
                                        //but when my input is in the array it can run
                                        canRun = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    if (canRun) {
        alert("yes this game can run");
    } else {
        alert("No, This game cannot run");
    }
};
函数setValue(){
myVariable=document.forms[“myform”][“gname”].value;
myVariable2=document.forms[“myform”][“gpc”].value;
myVariable3=document.forms[“myform”][“procesor”].value;
myVariable4=document.forms[“myform”][“ram”].value;
myVariable5=document.forms[“myform”][“os”].value;
var gname=[“波斯王子:被遗忘的沙子”,“战争的齿轮”,“是的”];
var gpc=[“Radeon HD 2600 Pro”、“GeForce 8600 GTS 512MB”、“ATI Radeon 5000系列”、“ATI Radeon 4000系列”、“ATI Radeon 3000系列”、“ATI Radeon HD 2900概述”、“ATI Radeon HD 2600概述”、“ATI Radeon X1950系列”、“ATI Radeon X1800系列”、“ATI Radeon X1650系列”];
var procesor=[“核心2双E45002.2GHz”,“Athlon 64 X2双核4400+”,“是”];
var ram=[“3 GB”、“2 GB”、“1 GB”];
var os=[“Windows Xp”、“Windows 7”、“Windows Vista”、“Windows 8”];
var canRun=false;
对于(i=0;i

演示:

这是因为循环变量
i
,在每个
for
循环中,您需要使用不同的循环变量,如
i、j、k、l
等。。。差不多

function setValue() {
    myVariable = document.forms["myform"]["gname"].value;
    myVariable2 = document.forms["myform"]["gpc"].value;
    myVariable3 = document.forms["myform"]["procesor"].value;
    myVariable4 = document.forms["myform"]["ram"].value;
    myVariable5 = document.forms["myform"]["os"].value;
    var gname = ["Prince of Persia: The Forgotten Sands", "Gears of War", "yes"];
    var gpc = ["Radeon HD 2600 Pro", "GeForce 8600 GTS 512MB", "ATI Radeon 5000 Series", "ATI Radeon 4000 Series", "ATI Radeon 3000 Series", "ATI Radeon HD 2900 Overview", "ATI Radeon HD 2600 Overview", "ATI Radeon X1950 Series", "ATI Radeon X1800 Series", "ATI Radeon X1650 Series"];
    var procesor = ["Core 2 Duo E4500 2.2GHz", "Athlon 64 X2 Dual Core 4400+", "yes"];
    var ram = ["3 GB", "2 GB", "1 GB"];
    var os = ["Windows Xp", "Windows 7", "Windows Vista", "Windows 8"];
    var canRun = false;
    for (i = 0; i < gname.length; i++)
    if (myVariable === gname[i]) //changed from 0 to i here
    {
        for (j = 0; j < gpc.length; j++) {
            if (myVariable2 === gpc[j]) //changed from 0 to i here
            {
                for (k = 0; k < procesor.length; k++) {
                    if (myVariable3 === procesor[k]) //changed from 0 to i here
                    {
                        for (l = 0; l < ram.length; l++) {
                            if (myVariable4 === ram[l]) //changed from 0 to i here
                            {
                                for (m = 0; m < os.length; m++) {
                                    if (myVariable5 === os[m]) //changed from 0 to i here
                                    {
                                        //but when my input is in the array it can run
                                        canRun = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    if (canRun) {
        alert("yes this game can run");
    } else {
        alert("No, This game cannot run");
    }
};
函数setValue(){
myVariable=document.forms[“myform”][“gname”].value;
myVariable2=document.forms[“myform”][“gpc”].value;
myVariable3=document.forms[“myform”][“procesor”].value;
myVariable4=document.forms[“myform”][“ram”].value;
myVariable5=document.forms[“myform”][“os”].value;
var gname=[“波斯王子:被遗忘的沙子”,“战争的齿轮”,“是的”];
var gpc=[“Radeon HD 2600 Pro”、“GeForce 8600 GTS 512MB”、“ATI Radeon 5000系列”、“ATI Radeon 4000系列”、“ATI Radeon 3000系列”、“ATI Radeon HD 2900概述”、“ATI Radeon HD 2600概述”、“ATI Radeon X1950系列”、“ATI Radeon X1800系列”、“ATI Radeon X1650系列”];
var procesor=[“核心2双E45002.2GHz”,“Athlon 64 X2双核4400+”,“是”];
var ram=[“3 GB”、“2 GB”、“1 GB”];
var os=[“Windows Xp”、“Windows 7”、“Windows Vista”、“Windows 8”];
var canRun=false;
对于(i=0;i