File type validation with Javascript

后端 未结 8 900
梦谈多话
梦谈多话 2020-12-09 22:52

I have a question regarding to JavaScript validation. I am validaing the whenever my scripts runs, it validates but also the action

8条回答
  •  无人及你
    2020-12-09 23:14

    var _URL = window.URL || window.webkitURL;
        $("input[type=file]").change(function(e) {
            var file;
                if ((file = this.files[0])) {
                    var img = new Image();
                    img.onload = function () {
                        // do to on load
                    };
                    img.onerror = function () {
                        alert("valid format " + file.type);
                    };
                    img.src = _URL.createObjectURL(file);
                }
        });
    

提交回复
热议问题