zoukankan      html  css  js  c++  java
  • php学习笔记之动态生成一组单选button

    <!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>动态生成一组单选button</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>


  • 相关阅读:
    python种的builtin函数详解第三篇 C
    python中的buildin函数详解(第一篇) C
    python中的formatter的详细用法 C
    python中的builtin函数详解第二篇 C
    python中函数的默认参数陷阱问题 C
    介绍C++11标准的变长参数模板
    猜数字
    父类和子类
    矩形的面积
    水果类
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/7396021.html
Copyright © 2011-2022 走看看