bootstrap-4 模态中的双滚动条

Posted

技术标签:

【中文标题】bootstrap-4 模态中的双滚动条【英文标题】:Double scrollbars in bootstrap-4 modal 【发布时间】:2019-04-01 09:56:03 【问题描述】:

$("div[id^='entry']").each(function()
  
  var currentModal = $(this);
  
  //click next
  currentModal.find('.btn-next').click(function()

    currentModal.modal('hide');
    currentModal.closest("div[id^='entry']").nextAll("div[id^='entry']").first().modal('show'); 
     
  );
  
  //click prev
  currentModal.find('.btn-prev').click(function()
 
    currentModal.modal('hide');
    currentModal.closest("div[id^='entry']").prevAll("div[id^='entry']").first().modal('show'); 

  );

);
    body.animsition.modal-open,body.animsition
        padding-right: 0!important;
            overflow: hidden!important;

    
    .modal.fade.show 
        overflow-x: hidden;
        overflow-y: auto;
    
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
     <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#data1">
                   View
                   </button>
                   <p>If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and javascript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:</p>
     <div class="modal fade" id="data1" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
          <div class="modal-dialog" role="document">
             <div class="modal-content">
                <div class="modal-header">
                   <h3 class="modal-title title" id="exampleModalLabel">Trade Details</h3>
                   <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                   <span aria-hidden="true">&times;</span>
                   </button>
                </div>
     
                <div class="modal-body">
                   <div class="card-body card-block">
                      <div class="displaydata">
                         <table class="table table-bordered">
                            <tbody>
                               <tr>
                                  <th scope="col">S.N</th>
                                  <th scope="row">1</th>
                               </tr>
                               <tr>
                                  <th scope="col">Company</th>
                                  <th scope="row">Mark Company</th>
                               </tr>
   
                            </tbody>
                         </table>
                      </div>
                   </div>
                </div>
                <div class="modal-footer">
                   <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                   <button type="button" class="btn btn-primary approve"   data-dismiss="modal" data-toggle="modal" data-target="#entry02">Approve
                   </button>
                   <input type="submit" class="btn btn-primary"  value="Edit">
                </div>
             </div>
          </div>
       </div>
       
       <div class="modal fade" id="entry02" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                <div class="modal-dialog" role="document">
                   <div class="modal-content">
                      <div class="modal-header">
                         <h3 class="modal-title title" id="exampleModalLabel">Pre-Payments/LC's Report Detail</h3>
                                 
                         <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                         <span aria-hidden="true">&times;</span>
                         </button>
                      </div>

                      <div class="modal-body">
                         <div class="card-body card-block">
                            <div class="displaydata">
                               <table class="table table-bordered">
                                  <tbody>
                                     <tr>
                                        <th scope="col">Due Date</th>
                                        <th scope="row">21st August</th>
                                     </tr>
                                     <tr>
                                        <th scope="col">As per PI Cash/TT/Advance </th>
                                        <th scope="row">210</th>
                                     </tr>
                                     <tr>
                                        <th scope="col">Incoming/Outgoing LC Number/ Value</th>
                                        <th scope="row">20</th>
                                     </tr>
                                             <tr>
                                  <th scope="col">Company</th>
                                  <th scope="row">Mark Company</th>
                               </tr>                               <tr>
                                  <th scope="col">Company</th>
                                  <th scope="row">Mark Company</th>
                               </tr>                               <tr>
                                  <th scope="col">Company</th>
                                  <th scope="row">Mark Company</th>
                               </tr>
                                  </tbody>
                               </table>
                            </div>
                         </div>
                         <div class="modal-footer">
                            <button type="button" class="btn btn-default btn-prev">Prev</button>
                            <button type="button" class="btn btn-default btn-next">Next</button>
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                            <input type="submit" class="btn btn-primary"  value="Edit">
                         </div>
                      </div>
                   </div>
                </div>
             </div>
         
          <div class="modal fade" id="entry03" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
             <div class="modal-dialog" role="document">
                <div class="modal-content">
                   <div class="modal-header">
                      <h3 class="modal-title title" id="exampleModalLabel">Sales and Purchase Report Detail</h3>
                              
                      <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                      <span aria-hidden="true">&times;</span>
                      </button>
                   </div>

                   <div class="modal-body">
                      <div class="card-body card-block">
                         <div class="displaydata">
                            <table class="table table-bordered">
                               <tbody>
                                  <tr>
                                     <th scope="col">Purchase/Sales Invoice Date</th>
                                     <th scope="row">1st October</th>
                                  </tr>


                               </tbody>
                            </table>
                         </div>
                      </div>
                      <div class="modal-footer">
                         <button type="button" class="btn btn-default btn-prev">Prev</button>
                         <button type="button" class="btn btn-default btn-next">Next</button>
                         <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                         <input type="submit" class="btn btn-primary"  value="Edit">
                      </div>
                   </div>
                </div>
             </div>
          </div>

我在使用 bootstrap-4 模式时有双滚动条。我已经尝试了所有可能的解决方案(使用 jQuery 和 css),但我无法达到我想要的结果。

如您所见,有两个滚动条。即使我在模式关闭时将正文溢出设置为自动,并且在模式打开时将溢出隐藏,也会出现一个滚动条,但它会向右移动到正文内容。由于我使用的是多个引导模态,在触发多个引导模态后,body上的modal-open类消失了。

【问题讨论】:

这可能会有所帮助。 ***.com/questions/16369718/… 感谢您的建议,但这不是我想要达到的结果 :) 【参考方案1】:

您是否尝试将其应用到您的 CSS 文件中?

html 
  overflow(x, y): hidden;

【讨论】:

你能给我们一些代码吗?从那张截图很难看出。那些双滚动条在 html 上吧? 我现在附上了代码sn-p。希望这有助于理解 应用此代码时,我的整个页面都缺少垂直滚动。【参考方案2】:

这里的问题似乎是“modal-open”类,当您打开下一个模态时,它并不总是添加到body(我认为这是由您的 hide() 和 show() 动作同时触发引起的时间)。

正是该类将滚动条移至您的身体:

.modal-open 
    overflow: hidden;

也许我找到了一个解决方案,而无需触及您的功能。我的解决方案对计算机说:“Ehi,机器!每次在页面中有模态显示时,在 &lt;body&gt; 中放置一个类 modal-open”。

为此,我使用了模态事件,您可以在此处找到文档:https://getbootstrap.com/docs/4.0/components/modal/

我只在你的脚本中添加了这个,CSS 不是必需的:

$('.modal').on('shown.bs.modal', function (e) 
  $("body").addClass("modal-open");
);

$("div[id^='entry']").each(function()
     
        var currentModal = $(this);
  
        //click next
        currentModal.find('.btn-next').click(function()

          currentModal.modal('hide');
          currentModal.closest("div[id^='entry']").nextAll("div[id^='entry']").first().modal('show'); 
           
        );
        
        //click prev
        currentModal.find('.btn-prev').click(function()
       
          currentModal.modal('hide');
          currentModal.closest("div[id^='entry']").prevAll("div[id^='entry']").first().modal('show'); 

        );
     
    );

    $('.modal').on('shown.bs.modal', function (e) 
      $("body").addClass("modal-open");
    );
  <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#data1">
                   View
                   </button>
                   <p>If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:</p>
     <div class="modal fade modal-1" id="data1" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
          <div class="modal-dialog" role="document">
             <div class="modal-content">
                <div class="modal-header">
                   <h3 class="modal-title title" id="exampleModalLabel">Trade Details</h3>
                   <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                   <span aria-hidden="true">&times;</span>
                   </button>
                </div>
     
                <div class="modal-body">
                   <div class="card-body card-block">
                      <div class="displaydata">
                         <table class="table table-bordered">
                            <tbody>
                               <tr>
                                  <th scope="col">S.N</th>
                                  <th scope="row">1</th>
                               </tr>
                               <tr>
                                  <th scope="col">Company</th>
                                  <th scope="row">Mark Company</th>
                               </tr>
   
                            </tbody>
                         </table>
                      </div>
                   </div>
                </div>
                <div class="modal-footer">
                   <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                   <button type="button" class="btn btn-primary approve" data-dismiss="modal" data-toggle="modal" data-target="#entry02">Approve
                   </button>
                   <input type="submit" class="btn btn-primary"  value="Edit">
                </div>
             </div>
          </div>
       </div>
       
       <div class="modal fade" id="entry02" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                <div class="modal-dialog" role="document">
                   <div class="modal-content">
                      <div class="modal-header">
                         <h3 class="modal-title title" id="exampleModalLabel">Pre-Payments/LC's Report Detail</h3>
                                 
                         <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                         <span aria-hidden="true">&times;</span>
                         </button>
                      </div>

                      <div class="modal-body">
                         <div class="card-body card-block">
                            <div class="displaydata">
                               <table class="table table-bordered">
                                  <tbody>
                                     <tr>
                                        <th scope="col">Due Date</th>
                                        <th scope="row">21st August</th>
                                     </tr>
                                     <tr>
                                        <th scope="col">As per PI Cash/TT/Advance </th>
                                        <th scope="row">210</th>
                                     </tr>
                                     <tr>
                                        <th scope="col">Incoming/Outgoing LC Number/ Value</th>
                                        <th scope="row">20</th>
                                     </tr>
                                             <tr>
                                  <th scope="col">Company</th>
                                  <th scope="row">Mark Company</th>
                               </tr>                               <tr>
                                  <th scope="col">Company</th>
                                  <th scope="row">Mark Company</th>
                               </tr>                               <tr>
                                  <th scope="col">Company</th>
                                  <th scope="row">Mark Company</th>
                               </tr>
                                  </tbody>
                               </table>
                            </div>
                         </div>
                         <div class="modal-footer">
                            <button type="button" class="btn btn-default btn-prev">Prev</button>
                            <button type="button" class="btn btn-default btn-next">Next</button>
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                            <input type="submit" class="btn btn-primary"  value="Edit">
                         </div>
                      </div>
                   </div>
                </div>
             </div>
         
          <div class="modal fade" id="entry03" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
             <div class="modal-dialog" role="document">
                <div class="modal-content">
                   <div class="modal-header">
                      <h3 class="modal-title title" id="exampleModalLabel">Sales and Purchase Report Detail</h3>
                              
                      <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                      <span aria-hidden="true">&times;</span>
                      </button>
                   </div>

                   <div class="modal-body">
                      <div class="card-body card-block">
                         <div class="displaydata">
                            <table class="table table-bordered">
                               <tbody>
                                  <tr>
                                     <th scope="col">Purchase/Sales Invoice Date</th>
                                     <th scope="row">1st October</th>
                                  </tr>


                               </tbody>
                            </table>
                         </div>
                      </div>
                      <div class="modal-footer">
                         <button type="button" class="btn btn-default btn-prev">Prev</button>
                         <button type="button" class="btn btn-default btn-next">Next</button>
                         <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                         <input type="submit" class="btn btn-primary"  value="Edit">
                      </div>
                   </div>
                </div>
             </div>
          </div>

编辑 1

也许我找到了一个好的解决方案!为此,我清理了一些代码,以便您更好地了解发生了什么。我将 cmets 添加到我编写的每个函数中。请注意,为简单起见,我还将“data-dismiss”属性添加到下一个和上一个按钮。我删除了你的循环,因为这里没有必要,我只创建了一个 onClick 事件。我在 Windows 上使用 Firefox、Chrome 和 IE11 进行了测试,一切正常。

试一试,如果有不明白的地方,请在 cmets 中告诉我。 :)

var padding_right,
    currentModal,
    my_block;

$(document).on('shown.bs.modal', '.modal', function () 
  padding_right=$("body").css("padding-right"); /* create a variable with padding-right when modal is shown */
);

$(document).on('hidden.bs.modal', '.modal', function () 
  /* This function is triggered when a modal is hidden and... */
  if($('.modal:visible').length) 
    $(document.body).addClass('modal-open').css("padding-right", padding_right); /* ...if there are some modal visible, it put on body class "model-open" & padding-right */
  else
    $(document.body).removeAttr("style"); /* ...if not remove only style attribute: having put "data-dismiss="modal on button next and prev modal.js automaticaly remove "modal-open" */
);


/* here I created only one function for our buttons, where I change only "my_block" with previus or next one. Your loop is not necessary */
$(".btn-next, .btn-prev").on("click", function(e)
  currentModal = $(this).closest(".modal");
  my_block= ($(this).hasClass("btn-next")) ? currentModal.nextAll("div[id^='entry']").first() : currentModal.prevAll("div[id^='entry']").first();

  my_block.modal('show');
);
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#data1">
                   View
                   </button>
                   <p>If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content Delivery Network).

MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include jQuery:</p>
     <div class="modal fade modal-1" id="data1" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
          <div class="modal-dialog" role="document">
             <div class="modal-content">
                <div class="modal-header">
                   <h3 class="modal-title title" id="exampleModalLabel">Trade Details</h3>
                   <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                   <span aria-hidden="true">&times;</span>
                   </button>
                </div>
     
                <div class="modal-body">
                   <div class="card-body card-block">
                      <div class="displaydata">
                         <table class="table table-bordered">
                            <tbody>
                               <tr>
                                  <th scope="col">S.N</th>
                                  <th scope="row">1</th>
                               </tr>
                               <tr>
                                  <th scope="col">Company</th>
                                  <th scope="row">Mark Company</th>
                               </tr>
   
                            </tbody>
                         </table>
                      </div>
                   </div>
                </div>
                <div class="modal-footer">
                   <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                   <button type="button" class="btn btn-primary approve" data-dismiss="modal" data-toggle="modal" data-target="#entry02">Approve
                   </button>
                   <input type="submit" class="btn btn-primary"  value="Edit">
                </div>
             </div>
          </div>
       </div>
       
       <div class="modal fade" id="entry02" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                <div class="modal-dialog" role="document">
                   <div class="modal-content">
                      <div class="modal-header">
                         <h3 class="modal-title title" id="exampleModalLabel">Pre-Payments/LC's Report Detail</h3>
                                 
                         <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                         <span aria-hidden="true">&times;</span>
                         </button>
                      </div>

                      <div class="modal-body">
                         <div class="card-body card-block">
                            <div class="displaydata">
                               <table class="table table-bordered">
                                  <tbody>
                                     <tr>
                                        <th scope="col">Due Date</th>
                                        <th scope="row">21st August</th>
                                     </tr>
                                     <tr>
                                        <th scope="col">As per PI Cash/TT/Advance </th>
                                        <th scope="row">210</th>
                                     </tr>
                                     <tr>
                                        <th scope="col">Incoming/Outgoing LC Number/ Value</th>
                                        <th scope="row">20</th>
                                     </tr>
                                             <tr>
                                  <th scope="col">Company</th>
                                  <th scope="row">Mark Company</th>
                               </tr>                               <tr>
                                  <th scope="col">Company</th>
                                  <th scope="row">Mark Company</th>
                               </tr>                               <tr>
                                  <th scope="col">Company</th>
                                  <th scope="row">Mark Company</th>
                               </tr>
                                  </tbody>
                               </table>
                            </div>
                         </div>
                         <div class="modal-footer">
                            <button type="button" class="btn btn-default btn-prev" data-dismiss="modal">Prev</button> <!-- add data-dismiss here to close automatically modals -->
                            <button type="button" class="btn btn-default btn-next" data-dismiss="modal">Next</button> <!-- add data-dismiss here to close automatically modals -->
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                            <input type="submit" class="btn btn-primary"  value="Edit">
                         </div>
                      </div>
                   </div>
                </div>
             </div>
         
          <div class="modal fade" id="entry03" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
             <div class="modal-dialog" role="document">
                <div class="modal-content">
                   <div class="modal-header">
                      <h3 class="modal-title title" id="exampleModalLabel">Sales and Purchase Report Detail</h3>
                              
                      <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                      <span aria-hidden="true">&times;</span>
                      </button>
                   </div>

                   <div class="modal-body">
                      <div class="card-body card-block">
                         <div class="displaydata">
                            <table class="table table-bordered">
                               <tbody>
                                  <tr>
                                     <th scope="col">Purchase/Sales Invoice Date</th>
                                     <th scope="row">1st October</th>
                                  </tr>


                               </tbody>
                            </table>
                         </div>
                      </div>
                      <div class="modal-footer">
                         <button type="button" class="btn btn-default btn-prev" data-dismiss="modal">Prev</button> <!-- add data-dismiss here to close automatically modals -->
                         <button type="button" class="btn btn-default btn-next" data-dismiss="modal">Next</button> <!-- add data-dismiss here to close automatically modals -->
                         <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                         <input type="submit" class="btn btn-primary"  value="Edit">
                      </div>
                   </div>
                </div>
             </div>
          </div>

【讨论】:

谢谢,双滚动条的问题消失了,但是当模态内容大于正文内容时,正文内容向右移动。当模态内容小于正文内容时,同样的问题加滚动条出现又消失:( 嗯...你完全正确,我没有注意到,对不起。顺便说一句,这是一个有趣的行为。现在我得去上班了,但今晚我会试着了解这里发生了什么。 ;) 当然,工作愉快。希望你能弄清楚代码中发生了什么:) 我编辑了我的答案。这次我希望你觉得它有用:) 非常感谢,它工作得非常好。但是当我关闭模式时,整个屏幕变成空白。我想我自己能弄清楚。再次感谢你:)【参考方案3】:

这就是我解决此问题的方法...当我打开/关闭模式时,我正在使用此 javascript 添加和删除 html 上的 modal-open

jQuery('.modal').on('shown.bs.modal', function (e) 
    jQuery("html").addClass("modal-open");
);
jQuery('.modal').on('hide.bs.modal', function (e) 
    jQuery("html").removeClass("modal-open");
);

对我来说,html 需要是 modal-open,即提供 overflow: hidden; 隐藏滚动条的样式。

【讨论】:

以上是关于bootstrap-4 模态中的双滚动条的主要内容,如果未能解决你的问题,请参考以下文章

使用 iframe 时如何摆脱双滚动条?

iframe框架嵌套页面(全屏,页面上下左右有空白,去双滚动条)

iframe 双滚动条解决

Laravel 刀片中的 bootstrap 4.x 模态

Bootstrap 4 模态中的 Cloudinary 响应式图像以适应移动屏幕

Material UI 自动完成 + 无限滚动在一起?