我正在使用脚本来创建图像上传预览图像(http://www.jqueryscript.net/demo/Image-Upload-Preview-Plugin-With-jQuery-Bootstrap-img-upload/) . 工作得很好,但我遇到了一些问题,在我的表单中我需要创建添加输入功能,在我的情况下,用户可以动态添加更多字段,如果我在我的html中插入多个输入文件字段,我没有问题,只有当我点击添加按钮创建新的输入字段时才会启动问题 . 某些事件被触发并开始显示仅在插入图像后显示的按钮 . 上面我给我的添加输入字段动态编码 .
JS:
//inputs
var max_fields = 10; //maximum input boxes allowed
var wrapper = $(".input_fields_wrap"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID
var x = 1; //initlal text box count
$(add_button).click(function(e) { //on add input button click
e.preventDefault();
if (x < max_fields) { //max input box allowed
x++; //text box increment
$(wrapper).append('
}
});
$(wrapper).on("click", ".remove_field", function(e) { //user click on remove text
e.preventDefault();
$(this).parent('div').remove();
x--;
})