Heartsuit's Simple Blog

A place to hold mainly reading notes, and some technical stuff occasionally. 这里主要是一些读书笔记、感悟;还有部分技术相关的内容。


Project maintained by heartsuit Hosted on GitHub Pages — Theme by mattgraham

Bootstrap如何弹出modal窗,并动态传值?

目录[-]

Let Code tell you

<div class="modal fade" id="qrcode" tabindex="-1" role="dialog" aria-labelledby="information">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">
          <span>&times;</span>
        </button>
        <h4 class="modal-title">请扫描二维码,完成支付</h4>
      </div>
      <div class="modal-body" style="text-align: center">
        <p id="message"></p>
        <img src="" alt="QRCode" id="scan">
      </div>
    </div>
  </div>
</div>
<button id="popup" class="btn  btn-primary btn-lg btn-block">我弹</button>
  $(function () {
    $('#popup').on('click', function(){
      $('#qrcode').modal('show');
    });
    $('#qrcode').on('show.bs.modal', function (event) {
      var modal = $(this);  //get modal itself
      modal.find('.modal-body #message').text('your message');
      modal.find('.modal-body #scan').attr("src", 'image src');
    });
  });

What does it look like

Modal Appearance


If you have any questions or any bugs are found, please feel free to contact me.

Your comments and suggestions are welcome!


「说点什么吧😊~~😊」: