如果宽度!= 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>
答案 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);
}
});