php dwz 三级联动下拉菜单

来源:互联网 发布:sql insert 长度限制 编辑:程序博客网 时间:2024/06/02 04:15

Tpl\ComBox\index.html:

[html] view plaincopy
  1. <h2 class="contentTitle">下拉菜单</h2>  
  2.   
  3. <div class="pageContent" layoutH="56">  
  4.     <select class="combox" name="province" ref="w_combox_city" refUrl="__URL__/returnCity/cityId/{value}">  
  5.         <option value="all">所有省市</option>  
  6.         <option value="bj">北京</option>  
  7.         <option value="sh">上海</option>  
  8.     </select>  
  9.     <select class="combox" name="city" id="w_combox_city" ref="w_combox_area" refUrl="__URL__/returnArea/areaId/{value}">  
  10.         <option value="all">所有城市</option>  
  11.     </select>  
  12.     <select class="combox" name="area" id="w_combox_area">  
  13.         <option value="all">所有区县</option>  
  14.     </select>  
  15. </div>  

Action\ComBoxAction.class.php:
[php] view plaincopy
  1. <?php  
  2. // 三级联动下拉菜单  
  3. class ComBoxAction extends CommonAction {      
  4.        
  5.     public function returnCity(){  
  6.         $cityId = $_REQUEST['cityId'];  
  7.         if($cityId=='sh'){  
  8.             $arrCity = array(array('all','所有城市'),array('sh','上海市'));  
  9.         }else if($cityId=='bj'){  
  10.             $arrCity = array(array('all','所有城市'),array('bj','北京市'));  
  11.         }else{  
  12.             $arrCity = array(array('all','所有城市'));  
  13.         }  
  14.          echo json_encode($arrCity);  
  15.     }  
  16.       
  17.     public function returnArea(){  
  18.         $areaId = $_REQUEST['areaId'];  
  19.         if($areaId=='sh'){  
  20.             $arrArea = array(array('1','上海城市1'),array('2','上海城市2'));  
  21.         }else if($areaId=='bj'){  
  22.             $arrArea = array(array('3','北京城市3'),array('bj','北京城市4'));  
  23.         }else{  
  24.             $arrArea = array(array('all','所有城市'));  
  25.         }  
  26.           
  27.          echo json_encode($arrArea);  
  28.     }  
  29.       
  30. }  
  31. ?>  

################################################################################

################################################################################

select联动效果:

模版代码:

<dl>
    <dt>品牌:</dt>
    <dd>
        <select class="combox required" name="pinpai_id" ref="jixing_id"
            refUrl="{{$smarty.const.__ROOT__?c=jixing&a=getJixing&pinpai={value}|url}}">
            <option value="">所有品牌</option>
            {{html_options options=$pinpaiArr selected=$info.pinpai_id}}
        </select>
    </dd>
</dl>
<dl>
    <dt>机型:</dt>
    <dd>
        <select class="combox required" name="jixing_id" id="jixing_id">
        <option value="">所有机型</option>
        {{html_options options=$jixingArr selected=$info.jixing_id}}
        </select>
    </dd>
</dl>

服务器端返回代码:

public function getJixingAction() {
    $pinpai = (int)$this->request('pinpai');
    $list = $this->cur_model->where('pinpai_id='.$pinpai)->order('id ASC')->select();
    $text = '[["", "所有机型"]';
    foreach ($list as $v) {
        $text .= ',["'.$v['id'].'", "'.$v['name'].'"]';
    }
    $text .= ']';
    exit($text);
}

原创粉丝点击