动态添加不在帖子中的输入字段

时间:2014-08-28 23:58:27

标签: jquery post http-headers

按下按钮时动态添加一些输入字段。但是当我发布表单时,动态添加的输入的后置值未设置

$('.addslidebutton').click(function(){
    i++;
    $('<div class="edit-slide"><div class="input "><label for="imageurl-new-'+i+'">Afbeeldings url</label><input name="imageurl-new-'+i+'" value="" class="" type="text" id="imageurl-new-'+i+'"></div><div class="input "><label for="linkurl-new-'+i+'">Link url</label><input value="" class="" type="text" id="linkurl-new-'+i+'" name="linkurl-new-'+i+'"></div><div class="input "><label for="tekst-new-'+i+'">tekst</label><input value="" class="" type="text" id="tekst-new-'+i+'" name="tekst-new-'+i+'"></div></div>').insertBefore('.addslidebutton');
});

输出html:

<div class="edit-slide">
   <div class="input "><label for="imageurl-new-1">Afbeeldings url</label><input name="imageurl-new-1" value="" class="elfinderselect" type="text" id="imageurl-new-1"></div>
   <div class="input "><label for="linkurl-new-1">Link url</label><input value="" class="" type="text" id="linkurl-new-1" name="linkurl-new-1"></div>
   <div class="input "><label for="tekst-new-1">tekst</label><input value="" class="" type="text" id="tekst-new-1" name="tekst-new-1"></div>
</div>

感谢阅读!

1 个答案:

答案 0 :(得分:0)

你要做的第一件事就是让你的代码易于开发,就像这样的

$('.addslidebutton').click(function(){
  var i = $(".edit-slide").length+1;
  $('<div class="edit-slide">\
    <div class="input ">\
      <label for="imageurl-new-'+i+'">Afbeeldings url</label>\
      <input name="imageurl-new[]" value="" class="" type="text" id="imageurl-new-'+i+'">\
    </div>\
    <div class="input ">\
      <label for="linkurl-new-'+i+'">Link url</label>\
      <input value="" class="" type="text" id="linkurl-new-'+i+'" name="linkurl-new[]">\
    </div>
    <div class="input ">\
      <label for="tekst-new-'+i+'">tekst</label>\
      <input value="" class="" type="text" id="tekst-new-'+i+'" name="tekst-new[]">\
    </div>\
   </div>').insertBefore('.addslidebutton')
});