2014-09-22 62 views
0

我使用一些附加形式的新数据,不存在在bootstrap 3模式中添加新的字段和克隆?

HTML

电话号码:

JS

$(document).ready(function(){ 
    var phone_number_form_index=0; 
    $("#add_phone_number").click(function(){ 
     phone_number_form_index++; 
     $(this).parent().before($("#phone_number_form").clone().attr("id","phone_number_form" + phone_number_form_index)); 
     $("#phone_number_form" + phone_number_form_index).css("display","inline"); 
     $("#phone_number_form" + phone_number_form_index + " :input").each(function(){ 
      $(this).attr("name",$(this).attr("name") + phone_number_form_index); 
      $(this).attr("id",$(this).attr("id") + phone_number_form_index); 
      }); 
     $("#remove_phone_number" + phone_number_form_index).click(function(){ 
      $(this).closest("div").remove(); 
     }); 
    }); 
}); 

,这里是工作提琴

http://jsfiddle.net/wc28f/3/

我试图添加到自举3模式,但我有没有运气,这里要说的是同样的代码在引导3模式

http://www.bootply.com/J9cv7EZv6K

是否可以扩展此exmaple喜欢选择,但我需要该数组的选择值

http://www.bootply.com/S9WGrK0WhL

这里是我的榜样,我需要的是

  • PHONE_NUMBER1 成为 PHONE_NUMBER [1],
  • 和qty1到成为数量[1]

回答

2

Working demo

我已删除线和它的工作

$("#phone_number_form" + phone_number_form_index).css("display","inline"); 

使用这样的:

$("#phone_number_form" + phone_number_form_index).removeClass("hidden"); 

你想phone_number[1]试试这个:

$(this).attr("name",$(this).attr("name") +"["+ phone_number_form_index+"]"); 

Updated DEMO

+0

这能更固定的$(this).attr(“name”,$(this).attr(“name”)+ ph one_number_form_index);变得像phone_number [1],所有其他元素可以在数组中,当提交时知道输入是在数组 – 2014-09-22 09:55:07

+0

可以ypu请检查我的编辑? – 2014-09-22 10:02:03

+0

@TanjaPakovic查看最新答案 – Manwal 2014-09-22 10:09:42