我對PHP(以及一般編程)非常陌生,我試圖讓我的表單域變得粘性,所以每次用戶點擊提交時,他們的選擇都保持在下拉菜單中。該代碼正在適當地改變字體,顏色等,但它會繼續回落到頂部的下拉值。讓我的下降粘滯?
<!DOCTYPE html>
<html>
<head><title>Example</title></head>
<body>
<form name="FontFamilyForm" method="post">
<select name="fontFamily">
<option value="serif">Serif</option>
<option value="sans-serif">Sans-serif</option>
<option value="fantasy">Fantasy</option>
<option value="monospace">Monospace</option>
</select>
<input type="submit" />
</form>
<form name="FontSizeForm" method="post">
<select name="fontSize">
<option value="100">Normal</option>
<option value="60">Tiny</option>
<option value="80">Small</option>
<option value="120">Medium</option>
<option value="150">Large</option>
<option value="200">Extra Large</option>
</select>
<input type="submit" />
</form>
<form name="BackgroundColorForm" method="post">
<select name="backgroundColor">
<option value="#ffffff">Normal</option>
<option name='beetch' value="#dddddd">Light Grey</option>
<option value="#aaaaaa">Medium Grey</option>
<option value="#888888">Grey</option>
<option value="#333333">Dark Grey</option>
<option value="#000000">Black</option>
</select>
<input type="submit" />
</form>
<?php
if (isset($_POST['fontFamily']))
{
$fontFamilyVar = $_POST['fontFamily'];
}
if (isset($_POST['fontSize']))
{
$fontSizeVar = $_POST['fontSize'];
}
if (isset($_POST['backgroundColor']))
{
$backgroundColor = $_POST['backgroundColor'];
}
?>
<style type="text/css">
body {
line-height:1.5;
width:640px;
margin:0 auto;
font-family: <?echo $fontFamilyVar?>;
font-size: <?echo $fontSizeVar?>%;
background-color: <?echo $backgroundColor?>;
color: #dddddd;
}
label {width:12em;float:left;}
</style>
<p>Test string blah blah blah blah blah</p>
</body>
<html>
非常感謝!這正是我所期待的! – Whoppa
@SamHenderson:聽起來像你應該接受這個答案(http://stackoverflow.com/help/someone-answers) – rici