在bootstrap 3模式中添加新的文件和克隆

Add new filed and clone in bootstrap 3 modal?

本文关键字:文件 添加 bootstrap 模式      更新时间:2023-09-26

我正在表单中使用一些不存在的附加新数据

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/

我正试图添加到bootstrap 3模式,但我没有运气,这是bootstrap 3模态中的相同代码

http://www.bootply.com/J9cv7EZv6K

确实可以扩展这个exmaple样的选择,但我需要的是选择值的后数组

http://www.bootply.com/S9WGrK0WhL

这是我的例子,我需要的是

  • phone_ number1变为phone_
  • qty1到变成数量[1]

工作演示

我已经删除了线路,它工作

$("#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+"]");

更新的演示