在 bootstrap 中创建模态

Creating modal in bootstrap

我在 Bootstrap、JQuery、HTML、CSS 上有一个网站 运行。 我想在我的网站上添加一个模态输出,这样当用户单击超链接时,一个模态将打开并打印一个 txt 文件的内容。 例如。我有两个包含不同详细信息的文本文件。而我的网站由句子 --> This is sam. This is his website 组成。我希望当用户点击 sam 或网站时,相应的文本文件以简单模式打开。

使用 bootstrap-modal 而不是使用 button 使用 a:

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>

<div class="container">
 
 
  <a href="#"  data-toggle="modal" data-target="#myModal">
    Open modal from a
  </a>

  <!-- The Modal -->
  <div class="modal" id="myModal">
    <div class="modal-dialog">
      <div class="modal-content">
      
        <!-- Modal Header -->
        <div class="modal-header">
          <h4 class="modal-title">Modal Heading</h4>
          <button type="button" class="close" data-dismiss="modal">&times;</button>
        </div>
        
        <!-- Modal body -->
        <div class="modal-body">
          Modal body..
        </div>
        
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
        </div>
        
      </div>
    </div>
  </div>
  
</div>
编辑给你评论

is there any way I could output the content of text file in that modal? E.g. to view http://humanstxt.org/humans.txt in the modal? Use:

$.get( "http://humanstxt.org/humans.txt", function( data ) {
  $('.modal-body').html= data;
});

.ajax:

$(document).ready(function(){
        $.ajax({url: "http://humanstxt.org/humans.txt", success: function(result){
            $('.modal-body').html(result);
        }});
});