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>.

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

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)