codecamp

PHP表单单选按钮

PHP教程 - PHP表单单选按钮

单选按钮用于从多个选项中进行单选。组中的所有单选按钮都具有相同的name属性。

每个组只能选择一个按钮。与复选框一样,使用value属性来存储发送到服务器的值(如果)按钮。

value属性对于复选框和单选按钮是必需的,并且对于其他字段类型是可选的。

<label for="radioButtonField1">A radio button field</label> 
<input type="radio" name="radioButtonField" id="radioButtonField1"  value="radio1" /> 
<label for="radioButtonField2">Another radio button</label> 
<input type="radio" name="radioButtonField" id="radioButtonField2"  value="radio2" /> 

您可以使用与预选复选框相同的方法预先选择单选按钮。



例子

以下脚本用于index.htm。它有一组单选按钮。

<html> 
 <body>                                  
  <form action="index.php" method="post">                                                
   <b>Please select your favorite color wine:</b> <br>             
   <input type="radio" name="color" value="white">  White           
   <input type="radio" name="color" value="rose">   Rose
   <input type="radio" name="color" value="red">    Red <br>
   <input type="submit" value="Submit This Form">
 </form>            
 </body>
</html>

以下脚本用于index.php。 它从上面的表单中读取数据。


<?php
  $color = $_POST["color"];
  if( ( $color != null ) )
  {
    $msg .= "a nice $color ";
    echo( $msg );
  }
?>


PHP表单选择
PHP表单隐藏字段
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

Operator

Introduction

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }