2016-07-13 3 views

答えて

1

フォームを送信する前にそれらをチェックすることができます。ファイルやブラウザがクライアント側の読み取りをサポートしていない場合に何が存在しない場合

window.URL = window.URL || window.webkitURL; 

    $("form").submit(function(e) { 
     var form = this; 
     e.preventDefault(); //Stop the submit for now 
            //Replace with your selector to find the file input in your form 
     var fileInput = $(this).find("input[type=file]")[0], 
      file = fileInput.files && fileInput.files[0]; 

     if(file) { 
      var img = new Image(); 

      img.src = window.URL.createObjectURL(file); 

      img.onload = function() { 
       var width = img.naturalWidth, 
        height = img.naturalHeight; 

       window.URL.revokeObjectURL(img.src); 

       if(width == 400 && height == 300) { 
        form.submit(); 
       } 
       else { 
        //fail 
       } 
      }; 
     } 
     else { //No file was input or browser doesn't support client side reading 
      form.submit(); 
     } 

    }); 
+0

はなぜフォームが提出する必要がありますか? – user2896120

関連する問題