Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 不使用提交按钮提交文件_Jquery_Html - Fatal编程技术网

Jquery 不使用提交按钮提交文件

Jquery 不使用提交按钮提交文件,jquery,html,Jquery,Html,我有一个项目,其中我有一个带有文件的表单… 如何在不使用提交按钮的情况下将表单提交给控制器操作?您有许多选项: 在选择文件事件回调时开始上载文件 单击html元素开始上载文件 上传显而易见的方式 您可以使用jQuery来实现您想要的。以下是从 尝试以下方法(使用普通javascript): 文件名: 函数submitForm(){ document.myForm.submit(); } <form id="target" action="destination.html">

我有一个项目,其中我有一个带有文件的表单…
如何在不使用提交按钮的情况下将表单提交给控制器操作?

您有许多选项:

  • 在选择文件事件回调时开始上载文件
  • 单击html元素开始上载文件
  • 上传显而易见的方式

  • 您可以使用jQuery来实现您想要的。以下是从

    尝试以下方法(使用普通javascript):

    
    文件名:
    
    函数submitForm(){ document.myForm.submit(); }
    <form id="target" action="destination.html">
      <input type="text" value="Hello there">
      <input type="submit" value="Go">
    </form>
    <div id="other">
      Trigger the handler
    </div>
    
    $( "#other" ).click(function() {
      //Do stuff, then submit
      $( "#target" ).submit();
    });
    
    <form action="upload_file.php" method="post"
    enctype="multipart/form-data" name="myForm">
    <label for="file">Filename:</label>
    <input type="file" name="file" id="file"><br>
    <input type="button" name="button1" value="Just a Button" onclick="submitForm()">
    </form>
    
    
    
    <script type="text/javascript">
     function submitForm() {
        document.myForm.submit();
     }
    </script>