简体   繁体   English

在弹出窗口中单击退出按钮时,防止重新加载父页面

[英]Prevent Parent page from reloading when exit button is clicked in popup

I have created a popup using modal. 我已经使用模式创建了一个弹出窗口。 When user clicks on a link it will show this modal popup. 当用户单击链接时,它将显示此模式弹出窗口。 I have put an exit button inside popup in order to close the popup. 我已经在弹出窗口中放置了退出按钮以关闭弹出窗口。 My problem is when i click on the exit button, the popups exits but the parent page gets reloaded. 我的问题是,当我单击退出按钮时,弹出窗口退出,但父页面被重新加载。

Is there any way to preventing the parent page from reloading. 有什么方法可以防止父页面重新加载。

Here is the code for modal popup: 这是模式弹出窗口的代码:

<div id="box-config-modal1" class="modal hide fade in" style="display: none;">
  <div class="box" id="box-details">
    <h4 class="box-header round-top">Details</h4>

    <div class="box-container-toggle" style="padding-left:20px;padding-right:20px;">
      <div class="box-content">
        <form name="popup" id="popup">
          <fieldset>

            <button class="close" data-dismiss="modal"></button>
            <h3>User Details</h3>

            <div class="control-group">

              <div class="controls">
                <label class="control-label" for="typeahead" style="width:100px;float:left;">Name </label><label id="advname" style="padding-left:150px;"></label>
              </div>
            </div>
            <div class="control-group">

              <div class="controls">
                <label class="control-label" for="typeahead" style="width:100px;float:left;">ID </label><label id="advid" style="padding-left:150px;"></label>
              </div>
            </div>
            <div class="control-group">

              <div class="controls">
                <label class="control-label" for="typeahead" style="width:100px;float:left;">Email </label><label id="email1" style="padding-left:150px;"></label>
              </div>
            </div>
            <div class="control-group">

              <div class="controls">
                <label class="control-label" for="typeahead" style="width:100px;float:left;">Country </label><label id="country" style="padding-left:150px;"></label>
              </div>
            </div>
            <div class="control-group">

              <div class="controls">
                <label class="control-label" for="typeahead" style="width:100px;float:left;">Website </label><label id="website" style="padding-left:150px;"></label>
              </div>
            </div>
            <div class="control-group">
              <div class="controls" id="newlist">
                <label class="control-label" for="typeahead" style="width:100px;float:left;">Change
                  History </label><label id="changehistory" style="padding-left:150px;"></label></div>
            </div>
          </fieldset>
        </form>
      </div>
    </div>
  </div>
</div>

Since your <form> doesn't have any submit button, so browser treating that button as submit button. 由于您的<form>没有任何提交按钮,因此浏览器将该按钮视为提交按钮。

So use this code 所以用这个代码

<button class="close" data-dismiss="modal" onclick="javascript:return false;"></button>

OR put this button outside <form> Tag 或将此按钮放在<form>标签之外

I assume, you are using bootstrap modal. 我认为,您正在使用引导程序模式。

You can create custom button to close bootstrap modal. 您可以创建自定义按钮以关闭引导程序模式。 Just check the following code 只需检查以下代码

<a href="#" class="my-close-btn">Close Popup</a>

$(function () {
    $(".my-close-btn").on('click', function() {
        $('#box-config-modal1').modal('hide');
        return false;
    });
});

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

相关问题 当单击按钮时,我希望多个选定的复选框行从弹出页面显示到父页面 - when the button is clicked i want the multiple selected checkbox row to be displayed from popup page to parent page 没有按钮时,如何防止获取请求重新加载 Javascript 中的页面? - How to prevent a fetch request from reloading the page in Javascript when there is not a button? 当点击“后退”按钮时,你可以停止重新加载前一页吗? - Can you stop a prior page from reloading when “back” button is clicked? 单击按钮并重定向到父窗口时显示状态弹出窗口-SpringBoot - Display a status popup when a button is clicked and redirect to the parent window - SpringBoot 阻止iframe重新加载父级 - Prevent Iframe from Reloading the Parent 阻止浏览器在重新加载父级时保留iframe url - Prevent browser from keeping iframe url when reloading the parent 如何防止Backbone应用程序中的“后退”按钮重新加载页面 - How to prevent Back button from reloading page in Backbone app 如何防止单击时按钮移动? - how to prevent a button from moving when clicked? 单击“输入”按钮时如何防止退出弹出窗口显示? - How to Prevent the Exit Popup From Showing When Clicking “INPUT” Buttons? 防止单击父类别单选按钮 - Prevent parent category radio button from being clicked
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM