简体   繁体   English

具有页面的Bootstrap模态弹出式窗口而无需刷新页面

[英]Bootstrap modal popup with page without page refresh

I am developing an application in ASP.Net using C#. 我正在使用C#在ASP.Net中开发应用程序。 In my page i am using JQuery and bootstrap for modal popup display. 在我的页面中,我正在使用JQuery和bootstrap进行模式弹出窗口显示。 I have taken some html button for display popup. 我已经采取了一些HTML按钮来显示弹出窗口。 But I am facing a problem to display modal popup. 但是我面临显示模式弹出窗口的问题。 When I am clicking on the button modal popup is showing and page is getting refreshed. 当我单击按钮时,将显示模式弹出窗口,并且页面正在刷新。 I don't know why is page getting refreshed. 我不知道为什么页面会刷新。 as per my knowledge JQuery works at client side. 据我所知,JQuery在客户端工作。

Please look at the following code of buttons. 请查看以下按钮代码。

<a id="editPhoto" class="btn btn-primary btn-sm" onclick="gen_all_es()" style="width:100%; margin-bottom:5px;" href="jcorp.aspx?paramControl=imagePhoto&responsePage=DesignCenter_Static.aspx&templateName=5">Add / Modify Photo</a>

<button id="editDesignation1" class="btn btn-primary btn-sm" style="width:100%; margin-bottom:5px;" data-target="#selectDesignation1_Modal" data-toggle="modal">Select Designation 1</button>
<button id="editDesignation2" class="btn btn-primary btn-sm" style="width:100%; margin-bottom:5px;" data-target="#selectDesignation2_Modal" data-toggle="modal">Select Designation 2</button>
<button id="editUploadLogo" class="btn btn-primary btn-sm" style="width:100%; margin-bottom:5px;" data-target="#selectLogo_Modal" data-toggle="modal">Select & Upload Logo</button>

Please help. 请帮忙。

Refer this site for model popup 请参阅此网站以获取模型弹出窗口

http://www.codeproject.com/Articles/589445/JavaScript-Modal-Popup-Window

Also check this code for your requirement 还要检查此代码是否符合您的要求

Page JavaScript: 页面JavaScript:

function myPop() { 
    this.square = null;
    this.overdiv = null;

    this.popOut = function(msgtxt) {
        //filter:alpha(opacity=25);-moz-opacity:.25;opacity:.25;
        this.overdiv = document.createElement("div");
        this.overdiv.className = "overdiv";

        this.square = document.createElement("div");
        this.square.className = "square";
        this.square.Code = this;
        var msg = document.createElement("div");
        msg.className = "msg";
        msg.innerHTML = msgtxt;
        this.square.appendChild(msg);
        var closebtn = document.createElement("button");
        closebtn.onclick = function() {
            this.parentNode.Code.popIn();
        }
        closebtn.innerHTML = "Close";
        this.square.appendChild(closebtn);

        document.body.appendChild(this.overdiv);
        document.body.appendChild(this.square);
    }
    this.popIn = function() {
        if (this.square != null) {
            document.body.removeChild(this.square);
            this.square = null;
        }
        if (this.overdiv != null) {
        document.body.removeChild(this.overdiv);
        this.overdiv = null;
        }

    }
}

Now the HTML page, using the JavaScript file: 现在使用JavaScript文件的HTML页面:

<html> 
  <head>
    <script type="text/javascript" src="NAME OF THE PAGE!.js"></script>
    <style>
        div.overdiv { filter: alpha(opacity=75);
                      -moz-opacity: .75;
                      opacity: .75;
                      background-color: #c0c0c0;
                      position: absolute;
                      top: 0px;
                      left: 0px;
                      width: 100%; height: 100%; }

        div.square { position: absolute;
                     top: 200px;
                     left: 200px;
                     background-color: Menu;
                     border: #f9f9f9;
                     height: 200px;
                     width: 300px; }
        div.square div.msg { color: #3e6bc2;
                             font-size: 15px;
                             padding: 15px; }
    </style>
  </head>
  <body>
    <div style="background-color: red; width: 200px; height: 300px;
                padding: 20px; margin: 20px;"></div>

    <script type="text/javascript">
        var pop = new myPop();
        pop.popOut("Test");
    </script>
  </body>
</html>

this is likely due to the href on the a tag for editPhoto causing the url refresh 这可能是由于editPhoto a标签上的href导致网址刷新

change your gen_all_es() function to use preventDefault on the event 更改您的gen_all_es()函数以在事件上使用preventDefault

html: 的HTML:

<a id="editPhoto" class="btn btn-primary btn-sm" onclick="gen_all_es(event)" style="width:100%; margin-bottom:5px;" href="jcorp.aspx?paramControl=imagePhoto&responsePage=DesignCenter_Static.aspx&templateName=5">Add / Modify Photo</a>

javascript: javascript:

function gen_all_es(e) {
    e.preventDefault();
    // your code
}

jsfiddle jsfiddle

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

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