jQuery 关闭颜色盒

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3316942/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 15:13:42  来源:igfitidea点击:

Closing Colorbox

jquerycolorbox

提问by Dofs

I have a simple popup (not an Iframe) where a user can send mail to each other. There is a submit button to send the information and a cancel button which should close the overlay.

我有一个简单的弹出窗口(不是 Iframe),用户可以在其中相互发送邮件。有一个用于发送信息的提交按钮和一个应关闭覆盖层的取消按钮。

I do have some trouble getting the close button to work.

我确实在让关闭按钮工作时遇到了一些麻烦。

The code looks like this:

代码如下所示:

<asp:Button runat="server" ID="btnCancel" Text="Cancel" />

<script type="text/javascript">
    jQuery(document).ready(function () {
        jQuery("#<%= btnCancel.ClientID %>").click(function () {
            jQuery.colorbox.close(); return false;
        });
    });
</script>

I have tried with both parent.jQuery.colorbox.close(), jQuery.fn.colorbox.close() but with no success.

我已经尝试过 parent.jQuery.colorbox.close(), jQuery.fn.colorbox.close() 但没有成功。

采纳答案by Dofs

I found out that I was adding jQuery and colorbox twice, since it was loaded both in the frame and the on the page calling colorbox.

我发现我添加了 jQuery 和 colorbox 两次,因为它在框架和页面上都加载了调用 colorbox。

It worked after I removed jQuery and Colorbox from the overlay page, so it only got included.

它在我从覆盖页面中删除 jQuery 和 Colorbox 后工作,所以它只被包含在内。

I used 'sushil bharwani' idea, and executed the close event.

我使用了“sushil bharwani”的想法,并执行了关闭事件。

回答by sushil bharwani

Does your colorbox have a close button at the top. [close]. In my application when i want to introduce a cancel button to close the colorbox window from a link other than already provided by colorbox.

您的颜色框顶部是否有关闭按钮。[关闭]。在我的应用程序中,当我想引入一个取消按钮以从 colorbox 已经提供的链接以外的链接关闭 colorbox 窗口时。

I do a workaround like.

我做了一个解决方法。

jQuery('#cboxClose').click();

this will click the default close button and will eventually close the colorbox.

这将单击默认关闭按钮并最终关闭颜色框。

回答by Ioannis Karadimas

You can use:

您可以使用:

$(window).colorbox.close();

回答by iPAS

Please try this.

请试试这个。

     <script type="text/javascript" charset="utf-8">
    $(document).ready(function() {
        /* Automatically resize to content */
        var y = $(document.body).height();
        var x = $(document).width();
        parent.$.colorbox.resize({innerWidth:x, innerHeight:y});

        $("#button_cancel").click(function() {
            parent.$.colorbox.close();
            return false;
        })
    });

For button on your iframe html page.

对于 iframe html 页面上的按钮。

  <button id="button_cancel" type="button">cancel</button>

回答by user950177

$(".selected_color").live('click',function(){

  $(window).colorbox.close();
});

Using live will work

使用 live 会起作用

回答by user950177

Perhaps this can help: http://jsfiddle.net/fbenariac/4vuDC/18/(It's a simple example for a colorbox close button).

也许这会有所帮助:http: //jsfiddle.net/fbenariac/4vuDC/18/(这是一个简单的颜色框关闭按钮示例)。

回答by Mayur bhalgama

I think you missing or mistake small thing in your code. Otherwise close method will work as expected. Have you check first that your button click fire or not? If fire, Have you got any JS error?

我认为您在代码中遗漏或弄错了小东西。否则 close 方法将按预期工作。你有没有先检查你的按钮点击是否触发?如果着火,你有任何 JS 错误吗?

回答by jean27

Did you try to use

你有没有尝试使用

$.fn.colorbox.close(); 

instead of

代替

jQuery.colorbox.close();

?

?

Maybe, you already did this:

也许,你已经这样做了:

 $("#cboxClose").click(function(){
      $.fn.colorbox.close();});

You must not have the problem on closing the colorbox. Actually, I also have a colorbox in an app with a cancel button and that close button which looks like an image. There's no problem at all.

您在关闭颜色框时一定没有问题。实际上,我在一个带有取消按钮和看起来像图像的关闭按钮的应用程序中还有一个颜色框。完全没有问题。

回答by Sthita

This may help someone .I have created a custom close button . My custom close button is coming on top right corner and can able to close also. My code :

这可能对某人有所帮助。我创建了一个自定义关闭按钮。我的自定义关闭按钮位于右上角,也可以关闭。我的代码:

        jQuery(document).ready(function(){
        jQuery('<div id="close" style="cursor: pointer; position: absolute; top: 0; right: 30px;"><img src="../img/close.png" alt="close"/></div>').appendTo('.yourparentDiv');

        $("#close").click(function() {
            jQuery('#cboxClose').click();
        });
    }); 

Thanks to @sushil bharwani , I was facing problem on closing the colorbox. It helped me.

感谢 @sushil bharwani ,我在关闭颜色框时遇到了问题。它帮助了我。