2013-11-25 93 views
-1

................................................ ....................................如何通過腳本調用showPreview_1(ele)的調用函數?

如何調用call函數showPreview_1(ele)by腳本?

.............................................. ......................................

<script language="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 != '500') 
      { 
      alert("not width 500 px."); 
      $('input').val(""); 
      } 
      else 
      { 
      #### call function showPreview_1(ele) #### 
      } 
     }; 
     img.src = _URL.createObjectURL(image_1); 
    } 
}); 
</script> 




<script language="JavaScript"> 
    function showPreview_1(ele) 
    { 
      $('#imgAvatar_1').attr('src', ele.value); // for IE 
      if (ele.files && ele.files[0]) { 

       var reader = new FileReader(); 

       reader.onload = function (e) { 
        $('#imgAvatar_1').attr('src', e.target.result); 
       } 

       reader.readAsDataURL(ele.files[0]); 
      } 
    } 
</script> 

回答

0

你可以試試這個,

 if (this.width != '500') 
     { 
     alert("not width 500 px."); 
      $('input').val(""); 
     } 
     else 
     { 
      showPreview_1(this); 
     } 
+0

謝謝,但爲什麼圖像不能預覽? – user3030013