简体   繁体   English

如何在用户触发后渲染模态

[英]How to render the modal after user trigger

Currently, my modal HTML codes are located below my original template. 目前,我的模态HTML代码位于我的原始模板下方。 Every time I load the page template, it will load that entire source codes included modal. 每次加载页面模板时,它都会加载包含模态的整个源代码。 Is there any way to load that modal HTML codes after the user clicks a button? 有没有办法在用户单击按钮后加载模态HTML代码?

HTML HTML

<!-- Template Codes-->
<button data-toggle="modal" data-target="#modal-content" type="button" ng-click="openModal()" class="btn btn-xs btn-default">
  <i class="fa fa-pencil"></i>
</button>

<!-- My Modal-->
<div id="modal-content" tabindex="-1" role="dialog" aria-hidden="true" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="block block-themed block-transparent remove-margin-b">
        <div class="block-header bg-primary-dark">
          <ul class="block-options">
            <li>
              <button data-dismiss="modal" type="button"><i class="si si-close"></i></button>
            </li>
          </ul>
          <h3 class="block-title">Content</h3>
        </div>
        <div class="block-content block-content-full">
          <!-- Some Contents-->
        </div>
      </div>
    </div>
    <div class="modal-footer">
      <button type="button" data-dismiss="modal" class="btn btn-sm btn-default">Close</button>
      <button type="button" data-dismiss="modal" ng-click="" class="btn btn-sm btn-primary"><i class="fa fa-check"></i> Update</button>
    </div>
  </div>
</div>

you have two way: 你有两种方式:

1- directly call modal using inline attr: 1-使用内联attr直接调用模态:

 <button data-toggle="modal" data-target="#modal-content" type="button" class="btn btn-xs btn-default" data-target="#modal-success-Public"> <i class="fa fa-pencil"></i> </button> 

2- use jQuery method: 2-使用jQuery方法:

 $("#modal-content").modal("show") 

for more details you can see this link 有关详细信息,您可以看到此链接

您可以在单独的html文件中指定模态模板,然后执行此操作。

<a data-toggle="modal" href="linktoyourmodaltemplate" data-target="#modal">Click me</a>

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

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