簡體   English   中英

克隆部分中的按鈕無法正常工作

[英]Buttons from cloned section not working properly

我是jquery腳本的新手。 我設法動態地克隆了表單的一部分,但是在克隆的部分中顯示ckeditor的div的按鈕不起作用。 當單擊原始按鈕時,它仍在偵聽原始部分中的按鈕,並且僅顯示ckeditor的div(但無法編輯除原始按鈕以外的所有div)。 這是我的代碼:

for(i=num; i<value; i++){
    var newSlot = $('#slot' + i).clone().attr('id','slot' + (i+1));

    newSlot.find('.heading-slot').attr('id', 'ID' + (i+1) + '_slot').html('Slot ' + (i+1)); //add new slot name

    newSlot.find('.other_message').hide();
    newSlot.find('.select_instruction').on('change', function () {  
        $(this).next('.other_message').toggle((this.value) == "Other")
    });


    newSlot.find('.extra_instruction').hide();
    //the button here is not working as I wanted
    newSlot.find('.btnAdditional').on('click', function(){
        $(this).next('.extra_instruction').show();
    });

    $('#slot' + i).after(newSlot);
}

HTML代碼

    <div class="col-sm-6">
        <button type="button" id="btn_Additional" name="btn_Additional" class="btnAdditional btn btn-info">Additional Instruction</button>
            <div class="extra_instruction">
                <textarea id="input_add_instruction" name="add_instruction[]" class="form-control"></textarea>
<script>CKEDITOR.replace( 'input_add_instruction' );</script>
            </div>
    </div>

有人可以指導我嗎? 請我對此很陌生。 在此先感謝..

clone函數不僅可以克隆html,還可以克隆事件監聽器,而不是克隆,請嘗試創建您的元素並正確添加事件監聽器。

暫無
暫無

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

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