php学习笔记之动态生成一组单选按钮
2015-06-02 14:00
736 查看
<!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=utf-8" /> <title>动态生成一组单选按钮</title> </head> <body> <table width="550" border="1" align="center" cellpadding="0" cellspacing="0"> <?php function GenerateRadioGroup($name, $options, $col, $default="") { $name = htmlentities($name); $len = count($options); $s = 1; //累计项目数量 $i = 0; foreach ($options as $value => $label) { if ($i == $col) //一行结束 { $html .= '</tr>'; $i = 0; } if ( $i % $col == 0) //一行开始 { $html .= '<tr>'; } if ($s == $len && $i < $col-1) { $colspan = $col - $i; $html .= '<td colspan="' . $colspan . '" >'; } else { $html .= '<td>'; } $value = htmlentities($value); $html .= '<input type="radio" '; if ($value == $default) { $html .= 'checked '; } $html .= 'name="' . $name . '" '; $html .= 'id="' . $name . '_' . $value . '" '; $html .= 'value="' . $label . '" />'; $html .= $label; $html .= '</td>'; ++$i; ++$s; } return $html; } $options = array("100", "400m", "1500m", "跳高", "立定跳远", "三级跳远", "铅球", "实心球", "三项全能", "接力赛"); $default = "2"; $col = 3; //表格的列数 $html = GenerateRadioGroup("RadioEvent", $options, $col, $default); echo $html; ?> </table> </body> </html>
相关文章推荐
- MTP
- PHP中new static()与new self()的区别异同分析
- IIS配置php运行环境默认加载的php.ini路径
- Mac OS X 10.9自带php-fpm的配置使用和扩展安装
- php异常处理—设置顶层异常处理器
- FragmentPagerAdapter与FragmentStatePagerAdapter区别
- php异常处理—重新抛出异常
- Yaf(Yet Another Framework)用户手册 yii框架手册
- php异常处理—多个异常
- phpstorm 8 注册码
- php B KB MB TB
- php异常处理—创建自定义的异常处理器
- 配置wamp开发环境
- PHP 中的新语法 new static 是个啥意思?
- php异常处理—异常的基本用法
- PHP的正则表达式手册
- ThinkPHP开发笔记-用户登录注册
- ortp编译测试
- YII excel导入
- TP excel 导入类