我想在执行PHP代码时清除或隐藏HTML文本(HTML表单)。
我只想展示 if (isset($_POST['submit'])) {}
以下是我在index.php中调用的代码。
<html>
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<body>
<div class="formku">
<legend><b>Input Score (0 - 4)</b></legend>
<form action="" method="post">
<legend><span class="number">1</span>N1 : </legend>
<input required type="text" name="n1" />
S1 :
<input required type="text" name="s1" /> <br/>
<legend><span class="number">2</span>N2 : </legend>
<input required type="text" name="n2" />
S2 :
<input required type="text" name="s2" /> <br/>
<input type="submit" name="submit" value="Count"/>
</form>
<hr>
<?php
if (isset($_POST['submit'])) {
$vn1 = $_POST['n1'];
$vn2 = $_POST['n2'];
echo '<h2>Result</h2>';
echo 'Final score N1 = ' . $vn1 * $vs1 . '<br>';
echo 'Final score N2 = ' . $vn2 * $vs2 . '<br>';
$tn = ($vn1 * $vs1) + ($vn2 * $vs2);
$ts = $vs1 + $vs2;
$ip = $tn / $ts;
echo 'IP Value: ' . $ip;
echo '<br>';
echo 'You got: ';
if ($ip >= 4)
echo 'A';
else if ($ip >= 3)
echo 'B';
else if ($ip >= 2)
echo 'C';
else if ($ip >= 1)
echo 'D';
else
echo 'E';
}
?>
</div>
</body>
</html>
答案 0 :(得分:2)
只需使用其他条件:
<?php
if (isset($_POST['submit'])) {
//show the message of submit
$vn1 = $_POST['n1'];
$vn2 = $_POST['n2'];
....
} else {
//show the form data
?>
<form ...>
</form>
<?php } ?>
答案 1 :(得分:0)
在if语句中,您可以回显以下内容:
<script type="text/javascript">
document.getElementsByClassName('formku')[0].display = "none";
</script>