Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.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
Jquery JS:For循环中的循环计数器总是未定义的_Jquery_For Loop - Fatal编程技术网

Jquery JS:For循环中的循环计数器总是未定义的

Jquery JS:For循环中的循环计数器总是未定义的,jquery,for-loop,Jquery,For Loop,我有一个JS函数来检查一个文件是否有一个有效的扩展名,并返回true或false来指示该文件是否可以接受 标记中有值的隐藏字段: <input id="hidAcceptedFormat" name="acceptedFileFormat" value="xls, xlsx, xlsb" type="hidden"> 以下是我的JS函数: function validateUploadedFileType(FileExtValue) { // Get list of a

我有一个JS函数来检查一个文件是否有一个有效的扩展名,并返回true或false来指示该文件是否可以接受

标记中有值的隐藏字段:

<input id="hidAcceptedFormat" name="acceptedFileFormat" value="xls, xlsx, xlsb" type="hidden">

以下是我的JS函数:

function validateUploadedFileType(FileExtValue) {    
// Get list of accepted file format from hidden fields
var hidAcceptedFileFormat = $('#hidAcceptedFormat').val();
// Split each file format and insert into array
var acceptedFileFormatList = hidAcceptedFileFormat.split(',');    
var blnValidateResult = false;    


// Loop each file format and check if file extension is belongs to one of the acceptable format    
for (var fileTypeLoopCnt = 0; fileTypeLoopCnt < acceptedFileFormatList.length; fileTypeLoopCnt++) {
    // If file extension is indeed one of the acceptable format
    if (FileExtValue == acceptedFileFormatList[fileTypeLoopCnt]) { // Problem: fileTypeLoopCnt is always undefined
        // Verify that this file is acceptable
        blnValidateResult = true;
        // Exit current loop once verified that this file is acceptable
        break;
    }

}
return blnValidateResult;
}
函数validateUploadedFileType(FileExtValue){
//从隐藏字段获取接受的文件格式列表
var hidAcceptedFileFormat=$('#hidAcceptedFormat').val();
//拆分每个文件格式并插入到数组中
var acceptedFileFormatList=hidAcceptedFileFormat.split(',');
var blnValidateResult=false;
//循环每个文件格式,并检查文件扩展名是否属于可接受的格式之一
对于(var fileTypeLoopCnt=0;fileTypeLoopCnt
我现在面临的问题是,当我在浏览器中调试时,循环中的
fileTypeLoopCnt
始终未定义

我尝试在for循环外声明一个变量,比如说
var ii++
,然后放入循环内,然后在下一个循环前增加计数器,比如
ii++
,但似乎循环内的任何内容都是未定义的


我在这里做错了什么?

//var acceptedFileFormatList=hideacceptedfileformat.split(',')是否在代码中实际注释?因为这可能是问题所在。

取消注释行//var acceptedFileFormatList=hideacceptedfileformat.split(',')


另外,请确保隐藏字段标记中的文件格式id为id='hidAcceptedFormat'

抱歉,我刚才对其进行了注释以供测试。实际代码没有注释掉,
acceptedFileFormatList
具有值。编辑代码更新代码以显示hidAcceptedFileFormat