dongqing220586 2015-08-23 12:37
浏览 97
已采纳

Semantic Ui Modal在重复调用时重复

I have a piece of jquery code which load a file as

$(".data_container").load(base_path+"sign_up/signup.php?trigger_id=random");

Signup.php contains

<?php include_once("../libs/php_header/php_header.php"); ?>

<div class="ui modal s_umodal">
<i class="close icon"></i>
<div class="header">
Modal Title
</div>
<div class="image content">
<div class="image">
An image can appear on left or an icon
</div>
<div class="description">
 A description can appear on the right
</div>
</div>
<div class="actions">
<div class="ui button">Cancel</div>
<div class="ui button">OK</div>
</div>
</div>

<script>
$('.s_umodal')

.modal('show');
</script>

The problem is, I can call the modal box and it shows up. but next time I click on the trigger button (button to show modal) it display another one even though I have closed the previous one. so now I am left with two modal boxes. and if I click multiple times i will be left with multiple modal boxes. I am using Semantic-UI.

  • 写回答

1条回答 默认 最新

  • douling6469 2016-01-01 04:28
    关注

    The problem with your implementation is that every time you call $('.data_container').load(base_path+"sign_up/signup.php?trigger_id=random"); you are creating a new dom element with the div you are fetching from that ajax call. $('.s_umodal').modal('show'); is then showing all of the modal boxes returned from the server.

    Without restructuring your code significantly, One approach is to not keep fetching the content of the div over and over again. The <div> will be a part of the main html that contains data_container. Your Ajax call can return the script that shows the dialog box.

    HTML:

    <div class="data_container"></div>
    <div class="ui modal s_umodal">
        <i class="close icon"></i>
        <div class="header">
          Modal Title
        </div>
        <div class="image content">
        <div class="image">
          An image can appear on left or an icon
         </div>
        <div class="description">
           A description can appear on the right
        </div>
       </div>
       <div class="actions">
       <div class="ui button">Cancel</div>
       <div class="ui button">OK</div>
      </div>
    </div>
    

    Your Ajax call could be returning:

    <script>
      $('.s_umodal').modal('show');
    </script>
    

    Your call to load the content could remain the same.

    $(".data_container").load(base_path+"sign_up/signup.php?trigger_id=random");
    

    If you are up for a significant change however, You can try to use JSON web services instead of returning <script>.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况