简体   繁体   English

从 DOM jQuery 添加输入后,Bootstrap 4 模态滚动不起作用

[英]Bootstrap 4 Modal scrolling not working after adding input from DOM jQuery

I am using Bootstrap 4 Modal and I have a UI something like this.我正在使用 Bootstrap 4 Modal,我有一个类似这样的 UI。

在此处输入图片说明

As you can see, I have Questions label and Add Question and by cliking on Add Question I can add new input boxes through jQuery.如您所见,我有问题标签和添加问题,通过单击添加问题,我可以通过 jQuery 添加新的输入框。 Here is my code how I am adding my new question.这是我如何添加新问题的代码。

$(document.body).on("click",".addSingle",function(){

       var appendX = '<div class="actionBtn"><div class="BtnIcon removeBtn removeSingle" title="Delete this choice."><svg class="svd-svg-icon" style="width: 16px; height: 16px;"><use xlink:href="#icon-inplaceplus"><symbol viewBox="0 0 12 12" id="icon-inplaceplus"><path d="M11 5H7V1H5v4H1v2h4v4h2V7h4z"></path></symbol></use></svg></div></div>';


       $(this).closest(".question_editable").find(".question:first").clone().find("input:text").val("").end().insertAfter($(this).closest(".question_editable").find(".question:last")).append(appendX);





   });

Now the thing is, as soon as I add more questions, I can see scroll but I am unable to scroll down.现在的问题是,只要我添加更多问题,我就可以看到滚动,但无法向下滚动。 Here is how the UI looks like when I am adding more questions.这是我添加更多问题时 UI 的样子。

在此处输入图片说明

As you can see above, I am not able to see Add Question text anymore because my Scroll not working however its showing.正如您在上面看到的,我无法再看到“添加问题”文本,因为我的 Scroll 无法正常工作,但它正在显示。

Now when I click on Edit Question and re-open the Edit Question modal which is another file with same modal code only modal id is different, its working fine like this.现在,当我单击“编辑问题”并重新打开“编辑问题”模态时,该模态是另一个具有相同模态代码的文件,只有模态 id 不同,它像这样工作正常。

在此处输入图片说明

Here in Edit Question I can add questions and my scroll also working fine.在“编辑问题”中,我可以添加问题,并且我的滚动条也可以正常工作。 So my though is my Add Question modal having some problem however my modal popups for Add Question and Edit Question modal question code structure is same.所以我虽然是我的添加问题模式有一些问题,但是我的添加问题编辑问题模式问题代码结构的模式弹出窗口是相同的。

Here is my Add Question modal popup same code looks like.这是我的添加问题模式弹出相同的代码。

<div class="modal fade" id="questionModal" tabindex="-1" role="dialog" aria-labelledby="questionModal"
   aria-hidden="true">
   <div class="modal-dialog modal-dialog-centered modalcustom" role="document">
      <div class="modal-content">
         <div class="modal-header">
            <h5 class="modal-title">Add Question</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
            </button>
         </div>
         <form role="form" method="POST" action="" novalidate id="questionModalfrm">
            @csrf
            <div class="modal-body">
            </div>
            <div class="modal-footer">
               <button type="submit" class="btn btn-br-success  btn-s-md  waves-effect waves-light">Add</button>
               <button type="button" class="btn btn-danger  btn-s-md  waves-effect waves-light" data-dismiss="modal">Cancel</button>
            </div>
         </form>
      </div>
   </div>
</div>

I have tried various options ( Bootstrap Modal Issue - Scrolling Gets Disabled ) by adding .modal { overflow-y:auto; }我通过添加.modal { overflow-y:auto; }尝试了各种选项( Bootstrap Modal Issue - Scrolling Gets Disabled.modal { overflow-y:auto; } .modal { overflow-y:auto; } but it doesnt work for me. .modal { overflow-y:auto; }但它不为我工作。

Snd here is my Edit Question HTML markup looks like. Snd 这是我的Edit Question HTML 标记的样子。

<div class="modal fade" id="questionModalEdit" tabindex="-1" role="dialog" aria-labelledby="questionModalEdit"
   aria-hidden="true">
   <div class="modal-dialog modal-dialog-centered modalcustom" role="document">
      <div class="modal-content">
         <div class="modal-header">
            <h5 class="modal-title">Edit Question</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
            </button>
         </div>
         <form role="form" method="POST" action="" novalidate id="questionModalEditfrm">
            @csrf
            <div class="modal-body">
            </div>
            <div class="modal-footer">
               <button type="submit" class="btn btn-br-success  btn-s-md  waves-effect waves-light">Save</button>
               <button type="button" class="btn btn-danger  btn-s-md  waves-effect waves-light" data-dismiss="modal">Cancel</button>
            </div>
         </form>
      </div>
   </div>
</div>

Can someone guide me what can I do to solve this ?有人可以指导我如何解决这个问题吗?

Okay. 好的。 Not sure I get your question entirely but I guess you're trying to keep the content of the modal scrolled to the end at all times. 不确定我是否完全收到您的问题,但我想您正在尝试始终将模式内容滚动到末尾。 You can just use the JS Scroll API. 您可以只使用JS Scroll API。

container.scrollTop = container.scrollHeight;

where container is the .modal-content 其中container是.modal-content

Would have been helpful if you could replicate something similar in jsfiddle for others to check what's causing the issue. 如果您可以在jsfiddle中复制类似内容供他人检查导致问题的原因,那将是有帮助的。

One option you could try is to have overflow only to your "questions" section rather than your modal and see if that works as expected. 您可以尝试的一种选择是仅使您的“问题”部分溢出,而不是使您的模态溢出,然后看看它是否按预期工作。

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

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