簡體   English   中英

如何刪除克隆HTML JQuery

[英]How can I remove clone HTML JQuery

我只是一個初學者,我想創建用於刪除克隆的按鈕,但我不能。 這是我的代碼,但是不起作用。 請幫助我知道我在哪里做錯了。

PS。 對不起,我英語不好

HTML

 <div class="docu">
      <div class="row">
         <div class="col-sm-2"></div>
            <div class="col-lg-7"  id="Freport" name="Freport">
              <div class="input-group">
                <div class="input-group-btn">
                    <select name="tell" id="tell" class="btn btn-default dropdown-toggle">
                        <option value="0"></option>
                        <option value="1"></option>
                        <option value="2"></option>
                        <option value="3"></option>
                    </select>
      </div><!--End row-->

      <input type="text" class="form-control" aria-label="..." placeholder="...">

      </div><!-- /btn-group -->
    </div><!-- /input-group -->

         <div class="col-sm-1">

<button type="submit" id="btnClonereport"><span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span></button>
<button type="submit" id="btnDelreport"><span class="glyphicon glyphicon-minus-sign" aria-hidden="true"></span></button>
</div>

<div id="container4">
</div>

JS這是我可以克隆的腳本,但不能刪除克隆。

<script type="text/javascript">
    $(function () {
        $("#btnClonereport").bind("click", function () {


            var index = $("#container4 select").length + 1;

            //Clone the DropDownList
            var fre = $("#Freport").clone();
            var fre2 = $("#orand").clone();


            //Set the ID and Name
            fre.attr("id", "Freport_" + index);
            fre.attr("name", "Freport_" + index);
            fre2.attr("id", "orand_" + index);
            fre2.attr("name", "orand_" + index);


            //[OPTIONAL] Copy the selected value
            var selectedValue = $("#Freports option:selected").val();
            fre.find("option[value = '" + selectedValue + "']").attr("selected", "selected");
            var selectedValue = $("#orands option:selected").val();
            fre2.find("option[value = '" + selectedValue + "']").attr("selected", "selected");

            //Append to the DIV.


            $("#container4").append(fre2);
            $("#container4").append(fre);
            $("#container4").append("<br /><br />");


        });
        $("#btnDelreport").bind("click", function(){
            $(this).closest("#container4").remove();
    });
    });

</script>

因此,您要刪除所有表單克隆嗎? 嘗試以下操作以執行刪除按鈕操作:

編輯:如果您想刪除最后一次出現,那會使事情變得簡單得多。

    $("#btnDelreport").bind("click", function(){
        $('#container4').children('.col-lg-7').last().remove();
    });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM