简体   繁体   English

用javascript隐藏它后重新加载div?

[英]Reload a div after i've hidden it with javascript?

This is probably a simple issue but i'm having a little trouble with it. 这可能是一个简单的问题,但是我遇到了一些麻烦。 I have created a form, this form uses php for validation of the fields. 我创建了一个表单,此表单使用php进行字段验证。 I have set-up an echo for the error message, this echos out in a pop-up window upon submission of the form. 我已经为错误消息设置了回显,在提交表单后会在弹出窗口中回显。

On this pop-up there is a close button, i've added some javascript to this button to hide the div so the user can continue filling out the form fields that they missed. 在此弹出窗口上,有一个关闭按钮,我向此按钮添加了一些JavaScript以隐藏div,以便用户可以继续填写他们错过的表单字段。 My only issue is... if the user submits the form again and it fails validation, the pop-up won't load as it has been hidden. 我唯一的问题是...如果用户再次提交表单并且验证失败,则该弹出窗口将被隐藏,因此不会加载。

How can I "temporarily" hide this div and reload it again upon submission? 如何“暂时”隐藏此div并在提交后重新加载? Here is my javascript code for the close button: 这是我的关闭按钮的JavaScript代码:

<script>
function checkClick(e) {
    var obj = e.srcElement;
    if (obj.id != 'pop-overlay')
        document.getElementById('pop-overlay').style.display = 'none';
    }
</script>

This is my call: 这是我的电话:

onClick="checkClick(event); return false;"

This is my php echo: 这是我的PHP回声:

<?php
        if(!empty($errorMessage)) 
        {
            echo("<div id='pop-overlay'><ol>" . $errorMessage . "</ol><img class='close' src='images/close-btn.png' onClick='checkClick(event); return false;'/></div>");
        } 
    ?>

I'm not sure I follow the page logic here, but if you want the div to show again on the same page, you would simply have to reshow the div with code like this: 我不确定这里是否遵循页面逻辑,但是如果您希望div在同一页面上再次显示,则只需使用以下代码重新显示div:

document.getElementById('pop-overlay').style.display = 'block';

You would put this code wherever you want it to start showing again. 您可以将此代码放在希望再次显示的位置。 If you need to remove the previous div from the page before you put a new one in the page, so that only the new one will show, then you can use this: 如果您需要先在页面上删除前一个div,然后再在页面上放置一个新的div,以便仅显示新的div,则可以使用以下方法:

var o = document.getElementById('pop-overlay');
o.parentNode.removeChild(o);

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

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