如果宽度如何删除文件!= 829 px和高度!= 90像素

时间:2013-11-25 04:40:41

标签: php jquery

如果宽度!= 829 px和高度!= 90 px

,如何从input type =“file”中删除文件

我使用this.value=""但不行,我该怎么办?

<script type="text/javascript">
    var _URL = window.URL || window.webkitURL;
    $("#image_1").change(function(e) {
        var image_1, img;
        if ((image_1 = this.files[0])) {
            img = new Image();
            img.onload = function() {
                if ((this.width != '728') && (this.height != '90'))
                {
                alert("not width 728 px and height 90 px.");
                this.value=""
                }
            };
            img.src = _URL.createObjectURL(image_1);
        }
    });
</script>

1 个答案:

答案 0 :(得分:0)

使用this question中的解决方案:

function resetFormElement(e) {
  e.wrap('<form>').closest('form').get(0).reset();
  e.unwrap();
}​

var _URL = window.URL || window.webkitURL;
$("#image_1").change(function(e) {
    var image_1, img;
    if ((image_1 = this.files[0])) {
        img = new Image();
        img.onload = function() {
            if ((this.width != '728') && (this.height != '90'))
            {
            alert("not width 728 px and height 90 px.");
            resetFormElement($(this));
            }
        };
        img.src = _URL.createObjectURL(image_1);
    }
});
相关问题