这样定义两个复选框:
<input type="checkbox" name="xuanze[]" id="xuanze[]" value="1"checked>
<input type="checkbox" name="xuanze[]" id="xuanze[]" value="2"checked>
怎样取得它们的value值?
我试过这种取法:$_POST['xuanze'][0],$_POST['xuanze'][1],结果失败了,请问谁知道怎么取得?

解决方案 »

  1.   

    <input type="checkbox" name="xuanze[]" id="xuanze[]" value="1" checked>if(!empty($_POST)){
      print_r($_POST);  #看其中打印的结果
      #应该是这样的:
      echo $_POST['xuanze0'];
      echo $_POST['xuanze1'];
    }
      

  2.   

    不会吧, 应该可以的.[User:root Time:04:06:45 Path:/home/apache/web]$ cat index.html 
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html;utf-8" />
    </head>
    <body>
    <form action="index.php" method="post">
    <input type="checkbox" name="xuanze[]" id="xuanze[]" value="1" checked />
    <input type="checkbox" name="xuanze[]" id="xuanze[]" value="2" checked />
    <input type="submit" value="submit" />
    </form>
    </body>
    </html>
    [User:root Time:04:06:51 Path:/home/apache/web]$ cat index.php 
    <?php
    print_r($_POST['xuanze']);
    ?>
    Array ( [0] => 1 [1] => 2 )
      

  3.   

    $_POST['xuanze0']这种写法不对吧
      

  4.   

    我试过多种方法结果显示这个checkbox的值是空的怎么办啊?
      

  5.   

    我试过多种方法结果显示checkbox的值是空的
      

  6.   

    你 print_r($_POST['xuanze']);看看结果就知道如何取值了
      

  7.   

    我就是不会这种数组形式的checkbox的value值的取法
      

  8.   

    不好意思能说详细点儿不?我是初学者,还有我用的是PHP语言,这个函数貌似不会用耶
      

  9.   

    我刚试了下这样写程序<?php print_r($_POST['xuanze[]']);?>,结果报出错误:Notice: Undefined index: xuanze in D:\wamp\www\checkbox.php on line 15
      

  10.   

    在此我非常抱歉,那段代码没测试,我有测试了一下,是这样:<?php
    if(isset($_POST)){
    print_r($_POST);
    #Array ( [id] => Array ( [0] => 3 [1] => 4 ) [del] => 删除 )
    #也就是说,name中[]会被解析为0,1……
    #$_POST['id'][0] => 3
    }
    ?><form id="form3" name="form3" method="post" action="test18.php">
      <p>
      <label for="id2">删除序号为</label>
      <input name="id[]" type="text" id="id2" size="10" value="3" />
      <input name="id[]" type="text" id="id2" size="10" value="3" />
      的记录
      </p>
      <p>
      <input type="submit" name="del" id="del" value="删除" />
      </p>
    </form>
      

  11.   


     print_r($_POST['xuanze']眼睛瞪大!!!!!!
      

  12.   

    好像问题有点跑偏啊我只是想知道向我上面定义的那种形式的checkbox的value值怎么取到,因为我可能要在下面的代码中做一些条件判断什么的
      

  13.   

    <?php
    #test18.php
    if(isset($_POST)){
    print_r($_POST);   #将这里打印出来看看
    #Array ( [xuanze] => Array ( [0] => 1 [1] => 2 ) [del] => submit )
    }
    ?>
    <form id="form3" name="form3" method="post" action="test18.php">
      <input type="checkbox" name="xuanze[]" id="xuanze[]" value="1" checked>
      <input type="checkbox" name="xuanze[]" id="xuanze[]" value="2" checked>
      <input type="submit" name="del" id="del" value="submit" />
    </form>
      

  14.   

    我运行出来了,那这里的checkbox的value值到底是不是这样写啊:$_POST['xuanze'][0],$_POST['xuanze'][1]?我知道运行结果表明第一个checkbox的value值是1第二个是2,但是那这个值要怎么表示啊?我利用$_POST取到的都是空值是怎么回事?
      

  15.   

    完全可以在接收页面处理接收到的参数啊,如果你非要这么做,那就在js中处理:<script>
    function ccc(){
      var href = "test18.php";
      //这里处理参数
      var param1 = "a=1";
      var param2 = "b=c";
      //这里将参数添加到url中
      document.form3.action=href+"?&"+param1+"&"+param2;
      document.form3.submit();
    }
    </script>
    <form id="form3" name="form3" method="post" action="">
      <input type="checkbox" name="xuanze[]" id="xuanze[]" value="1" checked>
      <input type="checkbox" name="xuanze[]" id="xuanze[]" value="2" checked>
      <input type="button" name="del" id="del" value="submit" onclick="ccc()" />
    </form>