查看: 1638|回复: 0

[PHP学习] 下拉框Option处理操作

发表于 2018-1-14 16:00:00
  1. `function getOption($list,$id,$key,$value,$default='顶级'){
  2. $htmls = array();
  3. $htmls[] = "<option value = '0' >".$default."</option>";
  4. foreach ($list as $key=>$value){
  5. $selected = "";
  6. if($v[$key]==$id)$seleected = "selected";
  7. $htmls = "<option value = '."$v[$key]".'".$selected.">".''$v[$value]."</option>";
  8. }
  9. return join("\n",$htmls);
  10. }
  11. function getTypeOptions($obj){
  12. $default = empty($obj->default)?'请选择类型':$obj->default;
  13. $list = M('goods_type')->field('type_id','type_name')->where('enabled=1')->select();
  14. $htmlOptions = getOption($list,$obj->id,'type_id','type_name',$default) ;
  15. return $htmlOptions;
  16. }`
复制代码


回复

使用道具 举报