简体   繁体   English

使用jQuery提交表单后隐藏一个div?

[英]hiding a div after submitting a form using jquery?

I am using a onclick function on my form submit button to hide a div. 我在表单提交按钮上使用onclick函数来隐藏div。 but it is not hiding. 但它没有隐藏。 what is the best way to do this? 做这个的最好方式是什么? I want to hide a div on my page, after submitting a form. 提交表单后,我想在页面上隐藏div。

<form action="" method="POST">
<input type="submit" onclick="hide_group_posts();">
</form>

<div id='div_i_want_to_hide'>
<?php include $_SERVER['DOCUMENT_ROOT']."page.php";?>
</div>

<script>
function hide_group_posts(){
$('#div_i_want_to_hide').hide();
}
</script>
$('form').submit(function(){
    $('#div_i_want_to_hide').hide();  
});

If it didn't help you, one of the following must be true: 如果对您没有帮助,则必须满足以下条件之一:

  • You didn't reference the jQuery library. 您没有引用jQuery库。
  • You didn't wrap the code with the DOM ready event. 您没有使用DOM ready事件包装代码。
  • You got typos. 你有错别字。
  • The submit function worked, and you got new page, because you didn't prevent the default. 提交功能有效,并且您得到了新页面,因为您没有阻止默认设置。

Prevent it like this: 防止这种情况:

$('form').submit(function(e){
    $('#div_i_want_to_hide').hide();  
    e.preventDefault();
    // Or with: return false;        
});

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

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