0

我正在使用 jquery.Form 与 jquery 一起上传。我想点击链接 Upload 1, Upload 2, Upload 3, Upload 4,打开选择文件的窗口并进行上传。以下代码仅在我仅按一次上传链接时才有效。如果我按一次上传 1(有效)和上传 2(无效),上传 3(无效),上传 4(无效)。

为什么?

<a href="#" class="open">Upload 1</a>
<a href="#" class="open">Upload 2</a>
<a href="#" class="open">Upload 3</a>
<a href="#" class="open">Upload 4</a>

<form id="myForm" action="upload.php" method="post" enctype="multipart/form-data">
     <input type="file" name="photo" class="input"  style="display: block; visibility: hidden;"/>
 </form>

<div id="message"></div>

<script>
$(document).ready(function() {

  $('.open').click(function(){
    $('.input').click();
    $('.input').change(function() {
        $('#myForm').submit();
    });  
});

var options = { 
  complete: function(response) 
  {
    $("#message").html("<font color='green'>"+response.responseText+"</font>");
  },
  error: function()
  {
    $("#message").html("<font color='red'> ERROR: unable to upload files</font>");
  }    
}; 

   $("#myForm").ajaxForm(options);
 });
</script>
4

0 回答 0