hidden隐藏域也是表单元素之一,它的语法和其他表单元素一样:
<input type="hidden" name="field_name" value="value">
那么hidden隐藏域到底有什么作用呢?
hidden隐藏域无外乎下面六点作用:
<?php
$num_to_guess = 42;
$message = "";
if (! isset ( $_POST ['guess'] )) {
$message = "Welcome!";
} else if ($_POST ['guess'] > $num_to_guess) {
$message = $_POST ['guess'] . " is too big!";
} else if ($_POST ['guess'] < $num_to_guess) {
$message = $_POST ['guess'] . " is too small!";
} else {
$message = "Well done!";
}
$guess = ( int ) $_POST ['guess'];
$num_tries = ( int ) $_POST ['num_tries'];
$num_tries ++;
?>
<html>
<head>
<title>html hidden隐藏域作用及用法实例介绍</title>
</head>
<body>
<?php print $message?>
Guess number: <?php print $num_tries?><br />
<form method="post" action="<?php
print $_SERVER ['PHP_SELF']?>">
<input type="hidden" name="num_tries"
value="<?php
print $num_tries?>" /> Type your guess here: <input type="text" name="guess" value="<?php
print $guess?>" />
</form>
</body>
</html>