如何从输入type="file"if-width中删除文件!=829 px和高度!=90像素
我使用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>
使用此问题的解决方案:
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);
}
});