Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 可重复块函数_Javascript_Jquery_Html - Fatal编程技术网

Javascript 可重复块函数

Javascript 可重复块函数,javascript,jquery,html,Javascript,Jquery,Html,我正在尝试在我的web表单中开发可重复块的功能,问题是当我单击按钮时,按钮什么也不做。我在控制台中测试了它们,它们确实工作,但它们什么也不做,不确定为什么,已经工作了2天,现在处于停滞状态,任何能为我指出正确方向的人都将不胜感激 它应该生成该字段集中包含的字段,并生成一个相同的空字段集,并且不确定加号或减号函数有什么问题 $('input, fieldset').each(function(){ if ($(this).attr('data-

我正在尝试在我的web表单中开发可重复块的功能,问题是当我单击按钮时,按钮什么也不做。我在控制台中测试了它们,它们确实工作,但它们什么也不做,不确定为什么,已经工作了2天,现在处于停滞状态,任何能为我指出正确方向的人都将不胜感激

它应该生成该字段集中包含的字段,并生成一个相同的空字段集,并且不确定加号或减号函数有什么问题

                   $('input, fieldset').each(function(){
        if ($(this).attr('data-maxOccurs') != 1){
            $(plusMinusButtons).insertAfter(this);
        }
    });
    $('.glyphicon-plus-sign').hover(function(){
                                                $(this).addClass('green');
                                              },
                                    function(){
                                                $(this).removeClass('green');
                                              }
                                    );
    $('.glyphicon-minus-sign').hover(function(){
                                                $(this).addClass('red');
                                               },
                                     function(){
                                                $(this).removeClass('red');
                                               }
                                    );
    $('body').on("click", '.glyphicon-plus-sign', function (){
                                                        prevInput = $(this).prev('input');
                                                        count = $(prevInput).attr('data-count');
                                                        countIncremented = count++;
                                                        br = '<br/><br/>';
                                                        inputElement = '<input type="'+$(prevInput).attr("type")+'" name="'+$(prevInput).attr("name")+countIncremented+'" data-count="'+countIncremented+'"/>';
                                                        $(br + inputElement + plusMinusButtons).insertAfter('.'+$(prevInput).attr("name")+':last');
                                                    }
                                );
    $('body').on("click", '.glyphicon-minus-sign', function (){
                                                        prevInput = $(this).prev('input');
                                                        $(this).remove(prevInput).remove(this);
                                                    }
                                );
    $("button").click(function(){
        console.log("here");
        x=$('#form').serializeArray();
        $.each(x, function(i, field){
          console.log(field.name + ":" + field.value + " ");
        });
    });
});

下面是JSFIDLE:

用于复制字段集的代码

$('body').on("click ", '.glyphicon-plus-sign', function() {
                        console.log("here ");
                        prevInput = $(this);
                        count = $(prevInput).attr('data-count=')||0;
                        countIncremented = count++;
                        br = '<br/><br/>';


                        $($(this).parent()).clone().insertAfter($(this).parent());

你的小提琴看起来不对劲。也许可以尝试更好地格式化HTML,以便在某些属性周围获得正确的引号。我认为问题现在已经解决,请告诉我是否正确,对我来说似乎没有问题此字段集标记的标记中有奇数个引号。这怎么可能是正确的呢?如果示例代码不依赖于特定属性,但仍然不正确,并且可能会掩盖其他错误或引入其他bug,那么它可能会起作用。