[英]Hide Form in HTML using Javascript
I have been trying to hide a form after the submit button is clicked. 单击提交按钮后,我一直试图隐藏表单。 I have googled and followed some but they seem to be not working for me.
我已经谷歌搜索并关注了一些,但它们似乎对我不起作用。
This is my code: 这是我的代码:
HTML: HTML:
<div id="wrapper">
<form name="regForm" id="regForm" action="indexSave.php" method="post">
<table width="100%" border="0">
<tr>
<td colspan="2"> <center> Registration Form </center> </td>
</tr>
<tr>
<td width="23%"> Name</td>
<td width="33%"> <input type="text" name="name" /> </td>
</tr>
<tr>
<td> Email Address</td>
<td> <input type="text" name="email" /></td>
</tr>
<tr>
<td> Contact Number</td>
<td> <input type="text" name="number" /></td>
</tr>
<tr>
<td> Message</td>
<td width="100"> <textarea name="msg"> </textarea> </td>
</tr>
<tr>
<td> <input onclick="myClick()" name="submit" id="submit" type="submit" value="Submit" /> </td>
<td> </td>
</tr>
</table>
</form>
</div>
And my Javascript: 而我的Javascript:
<script type="text/javascript">
function myClick()
{
var me = document.getElementById("wrapper").visibility="false";
}
</script>
I also tried this (from this link ) 我也尝试过这个(通过此链接 )
var me = document.getElementById("regForm").style.display="none";
Please help me figure out what's wrong? 请帮助我找出问题所在?
document.getElementById("regForm").style.display="none";
is enough to hide regForm
. 足以隐藏
regForm
。 Try to place your <script>
in <head>
. 尝试将
<script>
放在<head>
。
If hiding is all you want, you can have it with this really tiny piece of code: 如果只需要隐藏,则可以用这段很小的代码来实现:
<form onsubmit="this.style.display='none'" name="regForm" id="regForm" action="indexSave.php" method="post">
It will also hide the form when [enter] is pressed. 当按下[enter]时,它也将隐藏表格。
This code hides the form, reorganizing the other elements: 这段代码隐藏了表单,重新组织了其他元素:
<script type="text/javascript">
var form = document.getElementById("regForm");
function myClick(){
form.style.display = "none";
}
</script>
This code only makes it invisible, so if the code above is messing the layout, use it: 此代码仅使其不可见,因此,如果上面的代码使布局混乱,请使用它:
<script type="text/javascript">
var form = document.getElementById("regForm");
function myClick(){
form.style.visibility = "hidden";
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.