简体   繁体   English

如何在JavaScript中关闭颜色框

[英]How to close color box in JavaScript

I am using colorbox. 我正在使用colorbox。 I want open css-lightbox after close the colorbox. 我要在关闭颜色框后打开css-lightbox。 So my css-lightbox is ready and working fine. 这样我的css-lightbox就可以正常工作了。 But when I close colorbox then I have error in console. 但是,当我关闭colorbox时,控制台出现错误。

JavaScript code is: JavaScript代码是:

 $(".login_message").click(function(){
     $(".login_alert").hide();
     $(".emailNot").hide();
     $(".login_ok").hide();

     openforgotpw(); // open css-lightbox

     jQuery.fn.colorbox.close();   /* close the colorbox */

 });

Error is: 错误是:

Uncaught TypeError: Cannot call method 'close' of undefined 

Please help to close the colorbox. 请帮助关闭颜色框。 Thanks in advance. 提前致谢。

Usually, when the error is of the form Cannot call method 'X' of undefined, it means that whatever object you are attempting to call X from does not exist. 通常,当错误的形式为无法调用未定义的方法“ X”时,这意味着您尝试从中调用X的任何对象都不存在。

In your case, it appears as though 'close' is undefined. 在您的情况下,似乎“关闭”未定义。 The easiest way to resolve this involves: 解决此问题的最简单方法包括:

Make sure that none of your code executes until the browser is ready. 确保在浏览器就绪之前,任何代码都不会执行。 The best way to do this is to wrap all of your code within a .onReady() call. 最好的方法是将所有代码包装在.onReady()调用中。

Try with this 试试这个

parent.jQuery.fn.colorbox.close();

or you can try like this also 或者你也可以这样尝试

$(window).colorbox.close();

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

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