smarty 颜色选择框扩展

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */
 
 
/**
 * Smarty {color_options} function plugin
 *
 * Type:     function<br>
 * Name:     color_options<br>
 * Input:<br>
 *           - name       (optional) - string default "color"
 *           - selected   (optional) - string default not set
 * @author andsky <support#cd-dns.com>
 * @param array
 * @param Smarty
 * @return string
 */
function smarty_function_color_options($params, &$smarty)
{
 
    $name = empty( $params['name'] ) ? 'color' : $params['name'];
	$colors=array(
					"skyblue",
					"royalblue",
					"blue",
					"darkblue",
					"orange",
					"orangered",
					"crimson",
					"red",
					"firebrick",
					"darkred",
					"green",
					"limegreen",
					"seagreen",
					"teal",
					"deeppink",
					"tomato",
					"coral",
					"purple",
					"indigo",
					"burlywood",
					"sandybrown",
					"sienna",
					"chocolate",
					"silver"
				);
	$_html_result = '<option label="" value="">请选择颜色</option>'."\n";
	foreach ($colors as $c){
				$sel = '';
				if ( isset($params['selected']) && $params['selected'] == $c )
				{
					$sel = ' selected="selected"';
				}
 
				$_html_result .= "<option label=\"$c\" value=\"$c\" style=\"background-color:$c;color:$c\" $sel>$c</option>\n";
	}
 
	 $_html_result = '<select name="' . $name . '">' . "\n" . $_html_result . '</select>' . "\n";
 
    return $_html_result;
 
}
 
 
?>

发表评论

电子邮件地址不会被公开。 必填项已用*标注