以编程方式引导程序模式更改宽度

问题描述 投票:0回答:1

我需要通过jquery或普通javascript以编程方式更改模式的宽度。

这里是我所拥有的:

<div class="modal fade" id="modal-popup" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog modal-lg" role="document" id="modal_dialog">
    <div class="modal-content">
      <div class="modal-header">
                <h3 class="modal-title pull-left" id="action_title">My Title</h3>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
      </div>
      <div class="modal-body text-center">My Body</div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close Window</button>
      </div>
    </div>
  </div>
</div>

我似乎无法使用:

function popUpModal()
{  
   $('#modal-popup').modal('show');
   $('.modal-content').css('width','99%');  
   console.log('it is firing!');  
}

我在这里想念东西吗?

javascript jquery bootstrap-4
1个回答
1
投票

max-width.modal-dialog设置为99%。模态内容宽度已经是模态对话框的百分比。

function popUpModal()
{  
   $('#modal-popup').modal('show');
   $('.modal-dialog').css('max-width','99%');  
   console.log('it is firing!');  
}

popUpModal();
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<div class="modal fade" id="modal-popup" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog modal-lg" role="document" id="modal_dialog">
    <div class="modal-content">
      <div class="modal-header">
                <h3 class="modal-title pull-left" id="action_title">My Title</h3>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
      </div>
      <div class="modal-body text-center">My Body</div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close Window</button>
      </div>
    </div>
  </div>
</div>
热门问题
推荐问题
最新问题