admin管理员组

文章数量:1406177

I ran this code through Chrome and Firefox and it works well. Whenever I run it through Internet Explorer for testing purposes it will not work. I checked the javascript consule and I'm getting: SCRIPT5007: Unable to get value of the property '0': object is null or undefined. Can someone please tell me why this is ing up and what I can do to fix it?

$('#audiofile1').bind('change', function () {
    if (this.files[0].type != 'image/png') {
        $('#audiofile1').each(function () {
            $(this).after($(this).clone(true)).remove();
        });
        alert(this.files[0].name + ' is not a valid file type.');
    } else {
        if (this.files[0].size > '5000') {
            $('#audiofile1').each(function () {
                $(this).after($(this).clone(true)).remove();
            });
            var size = this.files[0].size;
            var maxSize = 100;
            var exceedingSize = size - maxSize;
            alert(this.files[0].name + ' exceeds the maximum file size');
        } else {
            $("#audiofile1").fadeTo(1500, 0.20);
            alert(this.files[0].name + ' was added successfully.');
        }
    }
});

I ran this code through Chrome and Firefox and it works well. Whenever I run it through Internet Explorer for testing purposes it will not work. I checked the javascript consule and I'm getting: SCRIPT5007: Unable to get value of the property '0': object is null or undefined. Can someone please tell me why this is ing up and what I can do to fix it?

$('#audiofile1').bind('change', function () {
    if (this.files[0].type != 'image/png') {
        $('#audiofile1').each(function () {
            $(this).after($(this).clone(true)).remove();
        });
        alert(this.files[0].name + ' is not a valid file type.');
    } else {
        if (this.files[0].size > '5000') {
            $('#audiofile1').each(function () {
                $(this).after($(this).clone(true)).remove();
            });
            var size = this.files[0].size;
            var maxSize = 100;
            var exceedingSize = size - maxSize;
            alert(this.files[0].name + ' exceeds the maximum file size');
        } else {
            $("#audiofile1").fadeTo(1500, 0.20);
            alert(this.files[0].name + ' was added successfully.');
        }
    }
});
Share Improve this question edited Jan 19, 2013 at 7:59 Ilmari Karonen 50.4k9 gold badges95 silver badges156 bronze badges asked Jan 19, 2013 at 7:33 user1661548user1661548 1
  • of your actual JSON object "this" u can post example? If it has trailing mas thats your problem – sajawikio Commented Jan 19, 2013 at 7:41
Add a ment  | 

3 Answers 3

Reset to default 2
if (this.files[0].type != 'image/png') {

Inside your event handler, jQuery makes this the DOM element for which the handler was registered. Either that element does not have a defined files property, or that property's value is null or undefined.

This is because Internet Explorer 9 and below do not support the File API. You should probably just skip binding the handler if the File API is not available:

if ($('#audiofile1')[0].files) {
    $('#audiofile1').bind('change', function () {
        // ...
    });
}

Apparently, IE only supports the HTML5 File API starting with version 10. Thus, in IE 9, there is no .files property to access at all.

Unfortunately, I don't know any way to work around this, except to tell your users to upgrade and/or to provide some alternative (likely server-side) method for users on older browsers to acplish whatever it is you're doing. In your case, assuming that you're eventually uploading the files to the server for further processing anyway, you could just skip the client-side checks on browsers that don't support them, and simply tell your users what kind of files will be accepted.

I am getting this (same/similar) error when attempting to Open a Jquery UI Dialog : SCRIPT5007: Unable to get value of the property '_focusTabbable': object is null or undefined.

The change that I made that appears to have caused this error...:
a) Change to Jquery 1.9.1
b) Change to Jquery UI 1.10.1
c) Added 'appendTo' option to the dialog invocation.

a) + b) > c)

I needed to do (c) because I had added (15) jquery dialogs to an existing page that previously had some subform elements disposed as hide/show div elements. I wanted to gain the jquery dialog functionality including modality. Problem was that the subform elements were rewritten by jquery by appending to the document, outside of the elements, thus formfields in the dialogs were no longer included when the form is submitted.

Anyway does anyone have a better solution than the above to this issue ?

本文标签: javascriptSCRIPT5007 Unable to get value of the property 39039 object is null or undefinedStack Overflow