我正在表单中使用一些不存在的附加新数据
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();
});
});
});
这是工作 fiddle
我正在尝试添加到 boostrap 3 模式,但我没有运气,这里是 bootstrap 3 模式中的相同代码
http://www.bootply.com/J9cv7EZv6K
是否可以像选择一样扩展此示例,但我需要发布该选择值的数组
http://www.bootply.com/S9WGrK0WhL
这是我的例子,我需要的是
- phone_number1 变成 Phone_number[1],
- 并且 qty1 变成 qty[1]
最佳答案
Working demo
我已经删除了线并且它起作用了
$("#phone_number_form" + phone_number_form_index).css("display","inline");
用这个:
$("#phone_number_form" + phone_number_form_index).removeClass("hidden");
您想要电话号码[1]
试试这个:
$(this).attr("name",$(this).attr("name") +"["+ phone_number_form_index+"]");
关于javascript - 在 Bootstrap 3 模式中添加新字段并克隆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25970487/