復(fù)選框字段是一個(gè)簡單的切換按鈕。它可以是開或關(guān)。
value屬性應(yīng)該包含在選中復(fù)選框時(shí)將發(fā)送到服務(wù)器的值。如果未選中復(fù)選框,則不會(huì)發(fā)送任何內(nèi)容。
<label for="checkboxField">A checkbox field</label> <input type="checkbox" name="checkboxField" id="checkboxField" value="yes" />
您可以通過向輸入標(biāo)記添加checked =“checked"屬性來預(yù)先選擇復(fù)選框:
<input type="checkbox" checked="checked" ... />.
通過創(chuàng)建具有相同name屬性的多個(gè)復(fù)選框字段,您可以允許用戶選擇同一字段的多個(gè)值。
以下腳本用于index.htm。 它有幾個(gè)復(fù)選框。
<html> <body> <form action ="index.php"> <ul> <li><input type ="checkbox" name ="chkFries" value ="11.00">Fries</li> <li><input type ="checkbox" name ="chkSoda" value ="12.85">Soda</li> <li><input type ="checkbox" name ="chkShake" value ="1.30">Shake</li> <li><input type ="checkbox" name ="chkKetchup" value =".05">Ketchup</li> </ul> <input type ="submit"> </form> </body> </html>
以下代碼用于index.php,它接受來自復(fù)選框的值。
<?PHP print "chkFries:" . $chkFries . "<br/>"; print "chkSoda:" $chkSoda . "<br/>"; print "chkShake:" . $chkShake . "<br/>"; print "chkKetchup" . $chkKetchup . "<br/>"; $total = 0; if (!empty($chkFries)){ print ("You chose Fries <br>"); $total = $total + $chkFries; } if (!empty($chkSoda)){ print ("You chose Soda <br>"); $total = $total + $chkSoda; } if (!empty($chkShake)){ print ("You chose Shake <br>"); $total = $total + $chkShake; } if (!empty($chkKetchup)){ print ("You chose Ketchup <br>"); $total = $total + $chkKetchup; } print "The total cost is \$$total"; ?>
更多建議: