简体   繁体   English

如何防止同一模态多次加载?

[英]How to prevent same modal from loading multiple times?

  • This is a rails application 这是一个Rails应用程序
  • Modal will be displayed by clicking on a link 单击链接将显示模态
  • The link will trigger an action in rails controller which will show the modal 该链接将在rails控制器中触发一个动作,该动作将显示模式
  • When double clicked on this link , the modal appears multiple times for each click until modal covers the page. 双击此链接时,每次单击都会多次出现模式,直到模式覆盖页面为止。
  • How to prevent double action trigger through link and display only one modal? 如何防止通过链接触发双向动作并仅显示一个模态?

Based on tag jquery in question. 基于有问题的标签jquery。 I assume you got something like this 我想你有这样的东西

$("#open-modal").on("click", function(){
    #ajax request
});

you should have some "flag" that will toggle between states "open", "closed" and based on it, it should close modal or send ajax. 您应该有一些“标志”,可以在状态“打开”,“关闭”之间进行切换,并根据此标志关闭模式或发送Ajax。

flag = {};
flag.is_open = false;
$("#open-modal").on("click", function(){
   if(!flag.is_open){ // so at first click result is true
      #ajax request
      #modal creation
      flag.is_open = true; // when user click second time you wont send ajax 
   }
});

 // and when u close

$("#close-modal").on("click", function(){
   if(flag.is_open){ // it is open
      #modal-destruction
      flag.is_open = false; 
   }
});

but you really should give us a piece of code so we could suggest something based on your work 但您确实应该给我们一段代码,以便我们可以根据您的工作提出一些建议

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

相关问题 如何阻止 useEffect 多次加载我的模态? - How to stop useEffect from loading my modal multiple times? 如何防止Vue多次加载数据? - How to prevent Vue from loading the data multiple times? 如何防止同一事件被多次绘制? 当前导致同一事件渲染的多层 - How To Prevent the Same Event From Being Painted Multiple Times? Currently Resulting in Multiple Layers of the Same Event Rendering 由于页面 iframe,防止内容脚本多次加载 - Prevent content script from loading multiple times due to page iframes 如何防止Firefox SDK内容脚本多次加载? - How do I prevent Firefox SDK content scripts from loading multiple times? 如何防止Google Chrome浏览器多次请求同一张图片? - How do I prevent Google Chrome from requesting the same image multiple times? asp.net:如何防止用户多次发布相同的数据 - asp.net: how do i prevent users from posting the same data multiple times 如何防止加载多个 React 副本? - How Prevent Multiple Copies Of React from Loading? 防止模态在页面加载期间闪烁 - Prevent modal from flashing during page loading 如何防止在jQuery的BS模式div中多次附加html? - How do you prevent appending html multiple times in BS modal divs in jQuery?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM