简体   繁体   English

如何在弹出窗口中插入关闭按钮

[英]How do I insert a close button inside my popup

I am generating a popup using b.popup, I want to include a close button "x" inside the popup but its not working. 我正在使用b.popup生成一个弹出窗口,我想在弹出窗口中包含一个关闭按钮“ x”,但它不起作用。

I have used it as follows: I dont have jquery installed hence I have to use the following script headers 我已按如下方式使用它:我没有安装jquery,因此必须使用以下脚本头

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://dinbror.dk/bpopup/assets/jquery.bpopup-0.9.4.min.js"></script>
<script src="http://dinbror.dk/bpopup/assets/jquery.easing.1.3.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/x.x.x/jquery.min.js"></script>
<script src="jquery.bpopup-x.x.x.min.js"></script>
<script>

This is the main script: 这是主要脚本:

(function($) 
{
    $(function() 
    {
        /*Popup for Details Button*/
        $('#btndetails').bind('click', function(e)
        {
            // Prevents the default action to be triggered. 
                e.preventDefault();
        $("#element_to_pop_up").html("Some text");
                $('#element_to_pop_up').bPopup();
        }
 });

})(jQuery);

This is the html button: 这是html按钮:

<input type="button" value="Details" id="btndetails" />
<div id="element_to_pop_up">
</div>

And this is the CSS: 这是CSS:

#element_to_pop_up
{ 
   background-color:#fff;
   border-radius:15px;
   color:#000;
   display:none; 
   padding:20px;
   min-width:400px;
   min-height: 180px;
}

I am getting a popup currently and inorder to close the popup I need to click outside the popup. 我现在正在弹出一个窗口,为了关闭该弹出窗口,我需要在弹出窗口之外单击。 How can I use a close button work? 如何使用关闭按钮? Please help me. 请帮我。

You are overriding the html with Jquery due to which , span class of close button is eliminating. 由于要消除关闭按钮的span类,因此您正在使用Jquery覆盖html。

http://jsfiddle.net/o9qoma1b/3/ http://jsfiddle.net/o9qoma1b/3/

see this fiddle i have fixed your code.Hope it helps you 看到这个小提琴,我已经修复了您的代码。希望对您有所帮助

css: CSS:

    #element_to_pop_up
    { 
       background-color:#fff;
       border-radius:15px;
       color:#000;
       display:none; 
       padding:20px;
       min-width:400px;
       min-height: 180px;
    }
    span.button.b-close {
    position: absolute;
    top: 5px;
    right: 8px;
    cursor:pointer;
    }

HTML: HTML:

<input type="button" value="Details" id="btndetails" />
<div id="element_to_pop_up">
  <span class="button b-close"><span>X</span></span>
</div>

JS: JS:

(function($) 
    {
               /*Popup for Details Button*/
            $('#btndetails').bind('click', function(e)
            {
                // Prevents the default action to be triggered. 
                    e.preventDefault();               
                    $('#element_to_pop_up').bPopup();
                    var html = $("#element_to_pop_up").html();
                    $("#element_to_pop_up").html(html+ "Some text");
            });  

    })(jQuery);

将此添加到您的HTML中,如果可能,还包括最新的JQuery。关闭

<a href="#" data-rel="back" data-role="button" data-theme="a" id="close-sub-cancel" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>

Try Something like this. 尝试这样的事情。

 function closeMsg() { $("msgBox").fadeOut(); } 
 <div id="msgBox"> <a href="javascript:closeMsg();" class="btn btn-success">No Thanks</a> </div> 

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

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