【问题标题】:Multiple forms with iput fields with the same name attribute具有相同名称属性的输入字段的多个表单
【发布时间】:2017-11-06 00:06:35
【问题描述】:

我有一个包含多个输入框的表单。并以这种形式进行多克隆。

如何使用 web py 将所有表单插入到数据库中?

这是克隆代码:

function resetForm($$form) {
    $$form.find('input:text, input:password, input:file, select, textarea').val('');
    $$form.find('input:radio, input:checkbox').removeAttr('checked').removeAttr('selected');
}
var count = 0;
var $$clonedata = $$('.form_data').clone();
resetForm($$clonedata);
$$(document).on('click', '.Add', function(e) {
    e.preventDefault();
    count++;
    $$clonedata.clone().appendTo('#form_data').attr('id','form_data');
  });

$$('#form_data').on('click', '.Remove', function(e) {
    e.preventDefault();
    $$(this).closest('.form_data').remove();
});

【问题讨论】:

  • 如果您向您展示 HTML,那么它会很容易为所有 SO 用户提供帮助。
  • 我认为只需一点improvement,您的问题可能看起来很多更好。看,我的编辑后它看起来有多好。你也可以做到。顺便说一句,目前还不清楚。

标签: jquery html web.py


【解决方案1】:

试试这个,

$(function() {
  function resetForm($form) {
    $form.find('input:text, input:password, input:file, select, textarea').val('');
    $form.find('input:radio, input:checkbox').removeAttr('checked').removeAttr('selected');
  }
  var count = 0;
  var $clonedata = $('.form_data').clone();
  resetForm($clonedata);
  $('.Add').on('click', function(e) {
    e.preventDefault();
    count++;
    $clonedata.clone().appendTo('#form_data').attr('id', 'form_data');
  });

  $('#form_data').on('click', '.Remove', function(e) {
    e.preventDefault();
    $(this).closest('.form_data').remove();
  });
  
  $('.Save').on('click', function(e) {
    e.preventDefault();
    console.log($('form').serialize());
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<a class="Add" href="#">Add</a>
<div id="form_data">
  <div class="form_data" style="margin:5px"> <input type="text" name="name1[]" value="" /> <input type="text" name="name2[]" value="" /> <button class="Remove">Remove</button>
</div>
</div>
<a class="Save" href="#">Save</a>

</form>

【讨论】:

  • 如何将所有
猜你喜欢
  • 2011-01-18
  • 2023-03-25
  • 2011-01-13
  • 2016-06-02
  • 2014-11-28
  • 2017-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多