如何使表单标签在单击“提交”后消失


how to make a form tag disappear after clicking submit

我想在点击提交按钮后让这个表单标签消失。我尝试使用"formaction",但它不允许我将数据添加到数据库中。我正在考虑使用JavaScript,但不知道如何使这种形式消失。

<form id ='eventdetail' name='eventform' method='POST' action="<?php $_SERVER['PHP_SELF']; ?>?month=<?php echo $month;?>&day=<?php echo $day;?>&year=<?php echo $year; ?>&v=true&add=true">
    <table width='400px' border='0'>
        <tr>
            <td width='150px'>Date</td>
            <td width='250px'><input type='text' name='txttitle' value ='<?php echo $month?>/<?php echo $day?>/<?php echo $year?>'></td>
        </tr>
        <tr>
            <td width='150px'>Title</td>
            <td width='250px'><input type='text' name='txttitle'></td>
        </tr>
        <tr>
            <td width='150px'>Detail</td>
            <td width='250px'><textarea name='txtdetail'></textarea></td>
        </tr>
        <tr>
            <td colspan='2' align='center'><input type='submit' name='btnadd' value='Add Event'></td>
        </tr>
    </table>
</form>

使用 javaScript 可以创建一个事件,然后将其绑定到提交按钮,

var hideForm = function() {  
  // to hide 
  var form = document.getElementById('eventdetail');
  form.style.display = 'none';
};

在你的从你可以做这样的事情。

<input type="submit" name="btnadd" value="Add Event" onclick="hideForm()">

在大多数网站上,提交按钮链接到另一个页面(它可能是没有表单的同一页面(,您可以在此处阅读有关提交按钮以及它们通常如何使用的更多信息 http://www.w3schools.com/html/html_forms.asp 向下滚动到"提交按钮"部分!

希望有帮助!

如果要保持在同一页面上而不刷新,可以使用 AJAX 发送表单的数据。之后,使用 JavaScript 让你的表单消失:函数是 removeChild((。