Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.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函数不适用于数组中的0值_Javascript_Arrays_Function_Menu_Indexing - Fatal编程技术网

JavaScript函数不适用于数组中的0值

JavaScript函数不适用于数组中的0值,javascript,arrays,function,menu,indexing,Javascript,Arrays,Function,Menu,Indexing,此函数用于在变量列表中查找最高的变量,这些变量有五个id字母和一个数字。它可以与所有其他插槽(2、3、4、5、6、7、8、9、10,但不是1)配合使用。我需要另一双眼睛 getVer函数从id中获取数字;所以getVer的ImpHt1是1,而getShtNm得到ImpHt function find_max_feat(array_input,ShtNm) { if (String(array_input[0]).length == 1) { var max = 0;

此函数用于在变量列表中查找最高的变量,这些变量有五个id字母和一个数字。它可以与所有其他插槽(2、3、4、5、6、7、8、9、10,但不是1)配合使用。我需要另一双眼睛

getVer函数从id中获取数字;所以getVer的ImpHt1是1,而getShtNm得到ImpHt

function find_max_feat(array_input,ShtNm) {
    if (String(array_input[0]).length == 1) {
        var max = 0;
    }
    else {
        var max = getVer(array_input[0]);
    }
    var maxver = 0
    var len = array_input.length;
    for (var i = 0; i < len; i++) {
        if (String(array_input[i]).length > 1) {
            if (getShtNm(String(array_input[i])) == ShtNm) {
                if (getVer(String(array_input[i])) > maxver) {
                    var max = array_input[i];
                    var maxver = getVer(String(array_input[i]));
                }
            }
        }
    }
    return max;
}
函数查找最大功能(数组输入,ShtNm){
if(字符串(数组_输入[0])。长度==1){
var max=0;
}
否则{
var max=getVer(数组_输入[0]);
}
var maxver=0
var len=数组_input.length;
对于(变量i=0;i1){
if(getShtNm(字符串(数组输入[i]))==ShtNm){
if(getVer(字符串(数组输入[i]))>maxver){
var max=数组_输入[i];
var maxver=getVer(字符串(数组输入[i]);
}
}
}
}
返回最大值;
}
0,DmnHt1_0,AltFm1_,0,0,0,0,0,0,0

数组的一个例子,这就是为什么需要getVer

这是一个图纸生成器,很清楚,但我已经为整个事情工作了至少几天了,甚至可能是一周或几周的工作

上面的数组在选择专长时生成,find_max_feat数组用于查找组中的最高版本;它在一个无限循环中运行,因为我所做的任何事情都不能使它按我所希望的方式工作

function checkFeats() {
    updateFeatsel();
    t=setTimeout("checkFeats()",1000);
}

function updateFeatsel() {
    curselarray = new Array();
    var selinc = 1;
    while (selinc <= 10) {
        var selincar = selinc - 1;
        var selid = document.getElementById(String('ftlst' + selinc));
        if (getVer(selid.options[selid.selectedIndex].title)) {
                curselarray[selincar] = selid.options[selid.selectedIndex].title;
        }
        else {
            curselarray[selincar] = 0;
        }
        selinc++;
    }
    document.getElementById('debug1').innerHTML = curselarray.valueOf();
    featSelch('hlthm','ImpHt',healthom);
    featSelch('strdmgm','ImpPd',Strpdom);
    featSelch('strwhtm','ImpLi',Strwhtom);
    featSelch('strsltm','EnhIt',StrSltom);
    featSelch('endsurm','ImpEn',EndSurom);
    featSelch('endsokm','ImpDf',EndSokom);
    featSelch('intelmpm','ImpMg',Intelmom);
    featSelch('willsokm','ImpMs',Willsokom);
    featSelch('luckrllm','ImpLu',Lukrllom);
    featSelch('luckpntm','EnhLu',Lukpntom);
    featSelch('hlthbn','DmnHt',0);
    featSelch('strbn','SupSt',0);
    featSelch('luckbn','DmnLu',0);
    featSelch('endbn','Armor',0)
    document.getElementById('debug2').innerHTML = find_max_feat(curselarray,'DmnHt');
    updateAmounts();
}

function featSelch(sid,fshtnm,defval) {
    return document.getElementById(sid).innerHTML = getFeatvalue(fshtnm,defval);
}
函数检查功能(){
updateFeatsel();
t=setTimeout(“checkFeats()”,1000);
}
函数updateFeatsel(){
curselarray=新数组();
var selinc=1;

而(selinc这是因为您正在使用
getVer(array\u input[0])
而不是
array\u input[0]
初始化
max
。如果第一项最高,版本号为零,则使用初始值

更改此项:

var max = getVer(array_input[0]);
进入:


不幸的是,这实际上似乎破坏了其他一切;现在返回的值代替了每个字段值,而不仅仅是它应该修改的值。@Daedalus:我不明白你的意思。什么是回显的,在哪里?修改在哪里?代码没有修改任何东西…函数在另一个字段中调用;让我现在就开始吧;我希望这能让事情变得明朗起来。如果我需要投入更多,请告诉我。@Daedalus:向我们扔越来越多的代码只会使事情变得复杂。制作一个测试用例。
var max = array_input[0];