设我们有一个html页面,代码如下:
复制代码 代码如下:
<form method=”post” action=”checktest.php”>
<input name=”test[]” type=”checkbox北大第一任校长” value=”1″ />
<input type=”checkbox” name=”test[]” value=”2″ />
<input type=”checkbox” name=”test[]” value=”3″ />
<input type=”checkbox” name=”test[]” value=”4″ />
<input type=”checkbox” name=”test[]R一个像夏天一个像秋天 歌词21; value=”5″ />
<input type=”submit” name=”submit” value=”submit” />
</form>
注意上面input的name属性,各个属性内容都一样,而且都是test[],加上[]的原因在于让test的内容变成数组形式传递。
checktest.php的代码内容如下:
复制代码 代码如下:
<?php
echo implode(“,”,$_post[‘test’]);
?>
我们输出内容时只需要注意利用implode函数将数组内容转化为字符串即可。
注:该功能可在删除多记录等场合运用。如delete from tbl where id in (implode(“,”,$_post[‘test’]))即可。
实例代码:
复制代码 代码如下:
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”content-type” content=”text/html; chart=gb2312″ />
<title>无标题文档</title>
</head>
<body>
html复选框如果要以数据组形式发送给php脚本处理浩浩荡荡是什么意思就必须以如checkbox[]这形式
<form id=”form1″ name=”form1″ method=”post” action=””>
<label>
<input type=”checkbox” name=”checkbox[]” value=”1″ />
</label>
<label>
<input type=”checkbox” name=”checkbox[]” value=”2″ />
</label>害群之马;
<label>
<input type=”checkbox” name=”checkbox[]” value=”www.jb51.net” />
</label>
<label>
<input type=”checkbox” name=”checkbox[]” value=”jb51.net” />
</label>
<label>
<医学input type=”submit” name=”submit” value=”提交” />
</label>
</form>
</body>
</html>
<?
//判断是否点击提交
if( $_post )
{
$array = $_post[‘checkbox’];
print_r($array);
}
/*
结果:
array
(
[0] => 1
[1] => 2
[2] => www.jb51.net
[3] => jb51.net
)
简单的很多事情在做之前觉得复杂但做起来就很容易了,像这个复选框代码就是这样了。
*/
?>
本文发布于:2023-04-06 13:17:27,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/801e7212298cec03e700314330d3ba6a.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:php checkbox 取值详细说明.doc
本文 PDF 下载地址:php checkbox 取值详细说明.pdf
留言与评论(共有 0 条评论) |