简体   繁体   English

如何清除内容div并使用JavaScript重新显示

[英]How to clear content div and reappear with javascript

I am using jQuery CustomBox modal. 我正在使用jQuery CustomBox模态。 I have it all working fine but I want the div behind it (BUT NOT THE BACKGROUND IMAGE) to disappear when modal is clicked. 我的所有功能都正常运行,但是我希望它后面的div(但不是背景图像)在单击模式时消失。 I have managed that, but not too sure on the code to make it reappear again after the modal is closed. 我已经做到了,但是在代码上不太确定,以确保在关闭模式后再次将其重新显示。 At the moment I have to refresh the page in order for it to come back. 目前,我必须刷新页面才能使其返回。

Here is the code I am using so far: http://codepen.io/doolz77/pen/esoHB/ 这是到目前为止我正在使用的代码: http : //codepen.io/doolz77/pen/esoHB/

I have not included the modal due to the amount of extra code, however, here is a link to the actual page 由于额外的代码量,我没有包含模式,但是,这是指向实际页面的链接

to make the modal appear just click on the 'joey' link. 要使模式出现,只需单击“ joey”链接。

Thanks! 谢谢!

EDIT: At the moment it is controlled by jQuery. 编辑:目前由jQuery控制。 The call which is placed in the footer is: 页脚中放置的呼叫为:

<script>
$(function () {
    $('#fadein').on('click', function () {
    $.fn.custombox( this {
    effect: 'fadein'
    });
    return false;
    });
});
</script>

This fades the modal in and out. 这使模态渐入渐出。 Would I just need to place some code here for the #wholePageContainer div to re-appear?? 我只需要在此处放置一些代码,以便#wholePageContainer div重新出现?

You need to store the html before deleting it to retrieve later. 您需要先存储html,然后再删除它以供以后检索。 Or you can use show/hide To reduce the pain and achieve desired functionality: 或者,您可以使用显示/隐藏来减轻痛苦并实现所需的功能:

function clearBox(wholePageContainer)
{
 document.getElementById(wholePageContainer).style.display = "none";
}
function showbox(wholePageContainer)
{
 document.getElementById(wholePageContainer).style.display = "block";
}

Demo 演示版

Is this what you were looking for: 这是您要找的东西吗?

http://codepen.io/anon/pen/giFEL

Edited: Explanation to the above link: In the above link i have made the html and body tag as 100% and the div element who's content is been removed to some percentage ie 50%, This will keep the div occupy space event if it is empty. 编辑:上面的链接的解释:在上面的链接中,我将html和body标记设为100%,将内容的div元素删除了某个百分比,即50%,如果它是,则将保留div占用空间事件空的。

Next i am storing the html content to a hidden div element and restoring it back to the div when required. 接下来,我将html内容存储到一个隐藏的div元素中,并在需要时将其还原回div中。

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

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