【问题标题】:Object form in javascript [duplicate]javascript中的对象形式[重复]
【发布时间】:2017-11-15 00:01:06
【问题描述】:

我想在表单中创建一个文件输入的对象表单,我该怎么做 .如何创建文件输入的表单对象

<html>
<head>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>

<form id="helooo">
  <input type="text" name="foo1" value="" />
  <input type="text" name="foo2" value="" id="r1"/>
<input type="file" name="f1" value="" id="r2"/>
<button type="submit" id="s1"> ab</button>
</form>




<script>
$(".quote_save").click(function() {
var oElements = {};
$('form'){
    oElements[this.name] =  = this.value;
});
});
</script>
</body>
</html>

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    试试下面的代码

    <script>
     $(".quote_save").click(function() {
    
      var formData=$('#helooo').serialize();
    });
    </script>
    

    【讨论】:

      【解决方案2】:

      首先你需要有方法和enctype(文件输入所必需的)。

      HTML:

      <form id="helooo" method="post" enctype="multipart/form-data">
        <input type="text" name="foo1" value="" />
        <input type="text" name="foo2" value="" id="r1"/>
      <input type="file" name="f1" value="" id="r2"/>
      <button type="submit" id="s1" class='quote_save'> ab</button>
      </form>
      

      Javascript:

      <script>
       $(function(){
       $(".quote_save").submit(function() {
        var form_data=$('#helooo').serialize();//string format
        var form_data=$('#helooo').serializeArray();//Arrayformat
      });
      });
      </script>
      

      参考:-/serialize

      【讨论】:

      • 你为什么要复制我的答案?
      • 你的回答和我的回答差别很大
      • 是的,只是你编辑...
      • 每个人都知道序列化,但你应该按照它的工作方式给出答案。
      • 大声笑你认为我不知道什么?如果您不复制我的答案,那么您的变量和我的变量如何相同。
      猜你喜欢
      • 1970-01-01
      • 2019-08-18
      • 2012-10-06
      • 2016-02-08
      • 1970-01-01
      • 2023-03-13
      • 2013-06-03
      • 1970-01-01
      • 2014-07-07
      相关资源
      最近更新 更多