Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.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
在ie9中不起作用的JavaScript files.length需要另一种方法_Javascript_Jquery_Internet Explorer - Fatal编程技术网

在ie9中不起作用的JavaScript files.length需要另一种方法

在ie9中不起作用的JavaScript files.length需要另一种方法,javascript,jquery,internet-explorer,Javascript,Jquery,Internet Explorer,我有以下JavaScript函数,它在internet explorer 9中声明变量filesattached的行中失败 function VesselDetails() { insurancestart = $('#ctl00_ContentPlaceHolder1_datetimepickerinsstart').val(); insuranceend = $('#ctl00_ContentPlaceHolder1_datetimepickerinsend')

我有以下JavaScript函数,它在internet explorer 9中声明变量
filesattached
的行中失败

function VesselDetails() {      

    insurancestart = $('#ctl00_ContentPlaceHolder1_datetimepickerinsstart').val();
    insuranceend = $('#ctl00_ContentPlaceHolder1_datetimepickerinsend').val();
    filesattached = $("input:File")[0].files.length;  

    //set up JS objects
    $('#ctl00_ContentPlaceHolder1_datetimepickerinsend').datetimepicker({ format: 'd/m/Y H:i a' });
    $('#ctl00_ContentPlaceHolder1_datetimepickerinsstart').datetimepicker({ format: 'd/m/Y H:i a' });

    //subscribe to change events
    $('#ctl00_ContentPlaceHolder1_datetimepickerinsstart').change(function () {
        insurancestart = $("ctl00_ContentPlaceHolder1_datetimepickerinsstart").val();
    });

    $('#ctl00_ContentPlaceHolder1_datetimepickerinsend').change(function () {
        insuranceend = $("ctl00_ContentPlaceHolder1_datetimepickerinsend").val();
    });

    $("input:File").change(function () {
        filesattached = $("input:File")[0].files.length;
    });

    ins_client();
}
ins\u client
方法如下所示:

function ins_client(sender, e) {
    if (pagemode == 'EditVessel') {
        e.IsValid = true;
    }

    if (pagemode == 'NewVessel') {
        if (insurancestart !== '' && insuranceend !== '' && filesattached > 0) {
            e.IsValid = true;
        }
        else {
            e.IsValid = false;
        }
    }
}

这一切在chrome和IE11中都能很好地工作,但是长度属性返回了一个未定义的IE9。我之所以使用长度,是因为我只希望在提交文件后,页面对新船舶请求有效,是否有其他方法可以在ie 9及chrome中使用,如果这已经在其他地方得到了回答,我很抱歉,但是我找不到任何地方可以让它以相同的方式继续工作,但在ie9和chrome中除外。

我担心这无法实现,ie9不支持HTML5文件API,因此它返回未定义的文件属性值

看一看

我替换了:

filesattached = $("input:File")[0].files.length;  
与:

VesselDetails
功能中

然后将
ins\u client
中的
if
语句替换为以下内容:

if (pagemode == 'NewVessel') {
        if (insurancestart !== '' && insuranceend !== '' && areFilesAttached == true) {
            e.IsValid = true;
        }
        else {
            e.IsValid = false;
        }
    }

这是一种替代方法,使我能够检查是否提供了文件,而不使用
files.length
属性,该属性与
IE9

不兼容,因为IE9不支持它。检查所有这些答案是否提及长度属性?检查对已接受答案的评论。因此,如果IE9不支持它,为什么这对我有帮助?知道前方道路已关闭且应该掉头不是很有帮助吗?
if (pagemode == 'NewVessel') {
        if (insurancestart !== '' && insuranceend !== '' && areFilesAttached == true) {
            e.IsValid = true;
        }
        else {
            e.IsValid = false;
        }
    }