按钮放置(添加一个字段设置,启用禁用按钮时,有多个)

Button Placement (Add with one field set, enable disable button when more than one)

本文关键字:按钮 启用 一个 添加 字段 设置      更新时间:2023-09-26

我需要确保只有一个加号按钮显示添加一个重复的字段集,如果只有一个,但添加删除按钮一旦重复创建,我有一个想法如何做到这一点通过分配一个数字值给每个重复的字段集创建,但我似乎不能让它工作,任何建议或指向正确的方向将是伟大的。

下面是当前时刻的代码,它将在单击按钮时复制字段设置:

       $('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());

我知道我需要给每个字段赋一个值,就像这样:

newNum  = new Number(num + 1),      
        newElem = $('#entry' + num).clone().attr('id', 'entry' + newNum);

但是不能让它工作,或者重构它以使它为我自己的应用程序工作。

JSFiddle Link:Fiddle Link

你总是可以使用if语句:

if ($('legend').length < n) { // n being whatever your base number of legends should be
 $('.glyphicon-minus-sign').css({ visibility: 'hidden'});
} else {
 $('.glyphicon-minus-sign').css({ visibility: 'visible'})
}

记住,jQuery选择器返回一个匹配选择器的元素数组。