如何添加或附加多个下拉列表

时间:2013-12-17 10:55:45

标签: javascript jquery html

我的任务是在点击添加按钮时添加上一个表单。 enter image description here

当我点击“添加”按钮时,它会在每个下方添加所有下拉菜单,如图所示。

删除一行(表示一行的所有5个下拉列表。)我将执行此功能。

问题是:

我们如何在每次点击添加按钮时添加或添加一行。

我的指点是: jQuery的:

$(document).ready(function () {
    $(".glyphicon").click(function () {
        $(this).parents('.form-group').remove();
    });
    $(".add").click(function () {
        $("form").parent(".form-group").add();
    });
});

$(document).ready(function () {
    $(".glyphicon").click(function () {
        $(this).parents('.form-group').remove();
    });
    $(".add").click(function () {
        $("form").parent(".form-group").add();
    });
});

HTML:

<div class="form-group">        
            <div class="col-sm-12" >
              <div class="btn-group week">
                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">All days
                  <span class="caret"></span>
                </button>
                <ul class="dropdown-menu">
                  <li class="week"><a href="#">Monday</a></li><li class="week"><a href="#">Tuesday</a></li>
                  <li class="week"><a href="#">Wednesday</a></li><li class="week"><a href="#">Thusday</a></li>
                  <li class="week"><a href="#">Friday</a></li><li class="week"><a href="#">Saturdayy</a></li>
                  <li class="week"><a href="#">Sunday</a></li>
                </ul>
             </div> 
             <div class="btn-group week">
                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">Time
                  <span class="caret"></span>
                </button>
                <ul class="dropdown-menu">
                  <li class="week"><a href="#">Monday-saturaday</a></li>
                </ul>
             </div> 
             <label for="exampleInputEmail1"> : </label>
              <div class="btn-group week">
                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">.00
                  <span class="caret"></span>
                </button>
                <ul class="dropdown-menu" style="height: 10em;width:2em;  overflow: auto;">
                  <li class=""><a href="#">.00</a></li><li class=""><a href="#">.01</a></li>
                  <li class=""><a href="#">.02</a></li><li class=""><a href="#">.03</a></li>                  
                  <li class=""><a href="#">.04</a></li><li class=""><a href="#">.05</a></li>                  
                  <li class=""><a href="#">.06</a></li><li class=""><a href="#">.07</a></li>                  
                </ul>
             </div>
              <label for="exampleInputEmail1"> to </label>
            <div class="btn-group week">
                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">Time
                    <span class="caret"></span>
                </button>
                <ul class="dropdown-menu">
                    <li class="week"><a href="#">Monday-saturaday</a></li>
                </ul>
            </div> 
            <label for="exampleInputEmail1"> : </label>
            <div class="btn-group week">
                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">.00
                  <span class="caret"></span>
                </button>
                <ul class="dropdown-menu" style="height: 10em;width:2em;  overflow: auto;">
                  <li class=""><a href="#">.00</a></li><li class=""><a href="#">.01</a></li>
                  <li class=""><a href="#">.02</a></li><li class=""><a href="#">.03</a></li>                  
                  <li class=""><a href="#">.04</a></li><li class=""><a href="#">.05</a></li>                  
                  <li class=""><a href="#">.06</a></li><li class=""><a href="#">.07</a></li>                  
                </ul>
             </div>
                <span class="glyphicon glyphicon-remove"></span>
          </div>
       </div>

2 个答案:

答案 0 :(得分:1)

尝试使用jQuery lib中的.clone()并简单地克隆最后一个元素。

Clone manual here

编辑: 这个问题的答案在下面的评论中(jQuery on()function)

答案 1 :(得分:0)

谢谢,我这样做了:

coading是:

 $("#add").click(function(){   
    $(".abcd:last").clone().appendTo(".wrapper");  
});

参考链接:

Cloning whole form elements after clicking button