zoukankan      html  css  js  c++  java
  • php怎么获取checkbox复选框的内容?

       由于checkbox属性,所有必须把checkbox复选择框的名字设置为一个如果checkbox[],php才能读取,以数据形式,否则不能正确的读取checkbox复选框的值哦。
    
    <form name="form1" method="post" action="">
    <label><input type="checkbox" name="checkbox[]" value="复选一"></label>
    <label><input type="checkbox" name="checkbox[]" value="复选二"></label>复选二
    <label><input type="checkbox" name="checkbox[]" value="复选三"></label>复选三
    <label><input type="checkbox" name="checkbox[]" value="复选四"></label>复选四
    
     
    
    <label><input type="submit" name="Submit" value="提交"></label>
    </form>
    <?php
    if( $_POST )
    {
    $value = $_POST['checkbox'];
    echo '你的选择:'.implode(',',$value);
    }
    ?>

    checkbox在php读取值时要用数组形式哦,我们读取这些值用php post获取是以一个array形式哦

     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
    <title>php获取多选框checkbox值</title> 
    </head> 
    <body> 
    <?php 
    $area_arr = array(); 
    if($_GET['action']=="submit"){ 
    $area_arr = $_POST['area']; 
    } 
    echo "您选定的地区为: "; 
    foreach ($area_arr as $k=>$v){ 
    echo $v." "; 
    } 
    ?> 
    <form id="form1" name="form1" method="post" action="?action=submit"> 
     河北 
    <label> 
    <input type="checkbox" id="area" name="area[]" value="河北"> 
    </label> 
      
     河南 
    <label> 
    <input type="checkbox" id="area[]" name="area[]" value="河南"> 
    </label> 
      
     山西 
    <label> 
    <input type="checkbox" id="area[]" name="area[]" value="山西"> 
    </label> 
      
     山东 
    <label> 
    <input type="checkbox" id="area[]" name="area[]" value="山东"> 
    </label> 
      
     江苏 
    <label> 
    <input type="checkbox" id="area[]" name="area[]" value="江苏"> 
    </label> 
      
     浙江 
    <label> 
    <input type="checkbox" id="area[]" name="area[]" value="浙江"> 
    </label> 
      
      
    <label> 
    <input type="submit" name="Submit" value="提交"> 
    </label> 
      
    </form> 
    </body> 
    </html> 
  • 相关阅读:
    将两个数组对比后合并为同一个数组
    invalid reference format: repository name must be lowercase
    Error: too many open files之ulimt
    vim打开文件末尾带有^M
    双层for循环体里,分别跳出外层循环和内层循环
    echarts 多饼图集合多标题
    近1个月订单占比城市TOP6
    javascript 显示日期
    国密SM2,SM4 For Delphi xe 10.3.3
    Datasnap POST 方案
  • 原文地址:https://www.cnblogs.com/kenshinobiy/p/4454188.html
Copyright © 2011-2022 走看看