简体   繁体   English

在表单提交后显示隐藏的div

[英]show a hidden div after form submit

I save the data using POST method from a form. 我使用表单中的POST方法保存数据。 After the data has been saved, page reloaded, I want to show a hidden div in the page. 保存数据后,重新加载页面,我想在页面中显示隐藏的div。

onsubmit="showHide(this); return false;" 

shows the specified div but does not save data. 显示指定的div但不保存数据。

any ideas? 有任何想法吗?

LE: LE:

to make it more complicated: the form that trigges the page reload is on the div that i want to re-show. 使其更复杂:触发页面重新加载的表单位于我想重新显示的div上。 initialy i make the div visible with: 最初我用以下方式使div可见:

<a class="articleLink" href="javascript:void(0);" onclick='$("#ModAdd<?php echo $rrows['id_']; ?>").show("slow");'></a>

No data will be sent since you have a return false; 由于您return false;因此不会发送任何数据return false; in your onSubmit . 在你的onSubmit

If you want the user to stay on the same page, you'll need Ajax . 如果您希望用户保持在同一页面上,您将需要Ajax Else, you have to show your div on the page that receives the data from your form. 否则,您必须在从表单接收数据的页面上显示您的div

You have to display the div after the reload. 您必须在重新加载显示div。
onsubmit will display it right away (on the same page). onsubmit会立即显示(在同一页面上)。 So check if the $_POST is set in php after reloading the site and then display the div 因此,重新加载网站后检查是否在PHP中设置了$_POST ,然后显示div

Example

<?php
if (isset($_POST)):
?>
    <div>Saved successfully</div>
<?php
endif;
?>

You might try something like this after reloading the page, instead of onsubmit : 重新加载页面后,您可以尝试这样的事情,而不是onsubmit

$POST = $POST['myPost'];
      $Message = '<script type="text/javascript">';
      $Message .= 'document.getElementById("' . $IDName . '").style.display="block";'; // Show the hidden DIV
      $Message .= 'document.getElementById("' . $IDName . '").innerHTML="' . $POST . '";'; // Output POST value
      $Message .= '</script>';
echo $Message;

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

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