2012-08-16 50 views
-1

如何編寫自動提交表單(用於文件上傳)?我試着在<input>字段添加onchange輸入文件和自動提交 - 播放框架2

@form(action = routes.Application.upload, 'enctype -> "multipart/form-data") { 
    <div class="fileupload fileupload-new" data-provides="fileupload"> 
     <span class="btn btn-large btn-primary btn-file"> 
      <span class="fileupload-new">Select file</span> 
      <span class="fileupload-exists">Change</span> 
     <input type="file" name="file" onchange="@routes.Application.upload()"/> 
     </span> 
     <span class="fileupload-preview"></span> 
     <a href="#" class="close fileupload-exists" data-dismiss="fileupload" style="float: none">&times;</a> 

     <input class="btn btn-success btn-large" type="submit" value="Submit!"> 

    </div> 
    } 

,但它不工作。有任何想法嗎?我正在使用Play Framework 2與Java

回答

1

您應該親自檢查它在代碼中的外觀。在你的onchange屬性中,你只需要一個url,對於瀏覽器來說它沒有明顯的含義。

相反,你應該把一些JavaScript方法的有名稱來執行,即:

<input type="file" name="file" onchange="this.form.submit()"/>