0

我正在尝试检查文件名变量是否为空。我用

$.each(rows, function(rowIndex, row){





        var fileName = $.trim(fields[0]).toLowerCase();

                //will output fileName 
        console.log(fileName );             

        //out -1,5,3,15,15,5,5,6,7,-1,3,5,5
                console.log(fileName.indexOf('.html'));     

        if(fileName.indexOf('.html') < 0 || window.location.href.toLowerCase().indexOf(fileName) < 0) //invalid or different file, skip this row
        {
            //if the filename is empty skip this loop and check next loop filename variable

            return true;
        }

        //the above script is to check to see if the filename is empty.         

                var $element = $('#' + fileName );

                //doesn't show anything at all.
                console.log(fileName );    

})

我的“if”语句之前的所有内容都会显示,但不会在它之后显示。

感谢您的帮助。

4

1 回答 1

0

您的 if 语句中包含“return true”。这将返回/完成您的主要功能。

改变:

如果添加之前:

var is_valid = false;

如果:

is_valid = true;

这样它就不会过早退出。'var' 是为了让这个变量在你的函数范围内是局部的,它不会泄漏内存。

于 2012-08-13T21:45:17.440 回答