【问题标题】:How to show a table when the submit button on a form is clicked单击表单上的提交按钮时如何显示表格
【发布时间】:2016-07-12 17:52:23
【问题描述】:

我目前正在做一个项目,以在用户输入教师 ID 时显示教师的时间表。我只想在他们单击提交后才显示表格,而不是在向他们询问 ID 时显示空表格。 这是我正在处理的代码的一部分。表格只应在点击提交按钮后显示。当前页面显示一个输入文本框、一个提交按钮和一个在点击提交按钮后填充的空表格。

<body>
<div class="container">
<h1>Faculty Timetable</h1>
<br> 
<form method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?>" >
Enter Faculty Employee ID:<input type="text" name="FacEmployeeId">   
<input type="submit" name="Submit">
<br><br>
<?php
//$facid="";
if($_SERVER["REQUEST_METHOD"]=="POST")
$facid=$_POST['FacEmployeeId'];
if(isset($facid)){
echo "<p align='center'><b>Timetable for Faculty ID ". $facid ."<br></b>               `   `</p>";}
?>
<br><br>
<table id="table_id" class="table table-bordered">
<thead>
<tr>
<th>         </th>
<th>8.00-8.50</th>
<th>9.00-9.50</th>
<th>10.00-10.50</th>
<th>11.00-11.50</th>
<th>11.50-13.00</th>
<th>13.00-13.50</th>
<th>14.00-14.50</th>
<th>14.55-.15.45</th>
<th>15.50-16.40</th>
<th>16.50-17.40</th>
</tr>
</thead>

【问题讨论】:

  • 如果您需要隐藏某些内容,请查看基本 CSS 教程。

标签: javascript php html css


【解决方案1】:

您可以在页面加载时将表格的属性保持为 display:none,一旦单击按钮,就可以调用一个函数,该函数将使表格 display:block。

<input type="submit" name="submit" onclick="func()">
<table id="tbl" style="display:none">
...
</table>

<script>
function func(){
 document.getElementById('tbl').style.display = 'block';
}
</script>

如果你愿意,你也可以使用 jquery 来做到这一点。

【讨论】:

  • 试过这个..当我点击提交按钮时表格会出现一秒钟然后消失
【解决方案2】:

无需 javascript 或无需 css 只需检查 $_POST 是否为 !empty 如果帖子不为空则显示表格

   <body>
    <div class="container">
    <h1>Faculty Timetable</h1>
    <br> 
    <form method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?>" >
    Enter Faculty Employee ID:<input type="text" name="FacEmployeeId">   
    <input type="submit" name="Submit">
    <br><br>
    <?php
    //$facid="";
if(!empty($_POST)){
    if($_SERVER["REQUEST_METHOD"]=="POST")
    $facid=$_POST['FacEmployeeId'];
    if(isset($facid)){
    echo "<p align='center'><b>Timetable for Faculty ID ". $facid ."<br></b>               `   `</p>";}
    ?>
    <br><br>
    <table id="table_id" class="table table-bordered">
    <thead>
    <tr>
    <th>         </th>
    <th>8.00-8.50</th>
    <th>9.00-9.50</th>
    <th>10.00-10.50</th>
    <th>11.00-11.50</th>
    <th>11.50-13.00</th>
    <th>13.00-13.50</th>
    <th>14.00-14.50</th>
    <th>14.55-.15.45</th>
    <th>15.50-16.40</th>
    <th>16.50-17.40</th>
    </tr>
    </thead>
<?php
}
?>

【讨论】:

  • 不,这不起作用..表格完全显示出来了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-03
  • 1970-01-01
  • 2013-11-21
  • 2017-05-08
相关资源
最近更新 更多