使用简单,可以单选也可以多选。一楼样式、演示、下载
******** 分割线 ********多选效果:userfun.php 代码//---------------------------结合项(案例)---------function retUrl($field, $fval, $mult = 1) { $urlPares = $GLOBALS['urlPares']; // 如果结合项字段在GET中,写入参数 foreach ($GLOBALS['fieldData'] as $key => $value) if (isset($_GET[$value])) $urlPares[$value] = $_GET[$value]; $res = ''; // 结合项单选 if (!$mult || !isset($_GET[$field])) { $copy = $urlPares; foreach ($fval as $key => $value) { $css = ''; // 如果url中有此参数 则删除 if (isset($_GET[$field]) && $_GET[$field] == $value) { unset($copy[$field]); $css = 'selected'; } else { $copy[$field] = $value; } $tpl = '/e/action/ListInfo.php?'.http_build_query($copy); $tpl = urldecode($tpl); $res .= sprintf(' <li><a class="%s" href="%s">%s</a> </li>', $css, $tpl, $value); } return $res; } // 结合项多选 // 如果url中不是数组形式 if (!is_array($_GET[$field])) { foreach ($fval as $key => $value) { $css = ''; // 如果当前值在url中 if ($value == $_GET[$field]) { $css = 'selected'; $copy = $urlPares; unset($copy[$field]); } else { $copy = $urlPares; $copy[$field] = array(); $copy[$field][] = $_GET[$field]; $copy[$field][] = $value; } $tpl = '/e/action/ListInfo.php?'.http_build_query($copy); $tpl = urldecode($tpl); $res .= sprintf('<li><a class="%s" href="%s">%s</a></li>', $css, $tpl, $value); } return $res; } // 数组形式的 foreach ($fval as $key => $value) { $css = ''; $copy = $urlPares; // 如果url中存在则删除 if (in_array($value, $copy[$field])) { unset($copy[$field][array_search($value, $copy[$field])]); $css = 'selected'; } else { $copy[$field][] = $value; } sort($copy[$field]); $tpl = '/e/action/ListInfo.php?'.http_build_query($copy); $tpl = urldecode($tpl); $res .= sprintf('<li><a class="%s" href="%s">%s</a></li>', $css, $tpl, $value); } return $res;} |
<?php$GLOBALS['urlPares'] = array( 'classid' => 1, // 栏目ID 'tempid' => 9, // 结合项列表模板ID 'ph' => 1, // 结合项字段,固定值不需要修改, 'line' => 3, // 每页显示条数);$GLOBALS['fieldData'] = array('myarea', 'sex', 'day');$a = retUrl('myarea', array('东城区', '西城区', '崇文区'), 1);$b = retUrl('sex', array('男', '女', '人妖'), 1);$c = retUrl('day', array(1,2,3,4,5,6,7), 1);?><div class="contianer"> <div class="h4"> <div class="sx">地区: <?=$a?></div> <div class="sx">性别: <?=$b?></div> <div class="sx">星期: <?=$c?></div> </div></div> |
很赞哦 ()