简体   繁体   English

克隆部分中的按钮无法正常工作

[英]Buttons from cloned section not working properly

I'm new to jquery scripts. 我是jquery脚本的新手。 I managed to clone one section of the form dynamically but my button to display the ckeditor's div in the cloned section is not working. 我设法动态地克隆了表单的一部分,但是在克隆的部分中显示ckeditor的div的按钮不起作用。 It still listening to the button from the original section and will only show the ckeditor's div(but unable to edit all of them except the original) when the original button was clicked. 当单击原始按钮时,它仍在侦听原始部分中的按钮,并且仅显示ckeditor的div(但无法编辑除原始按钮以外的所有div)。 Here is my code:- 这是我的代码:

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 code 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>

Can anyone guide me on this?? 有人可以指导我吗? Please I'm very new to this. 请我对此很陌生。 Thanks in advances.. 在此先感谢..

clone函数不仅可以克隆html,还可以克隆事件监听器,而不是克隆,请尝试创建您的元素并正确添加事件监听器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM