Thinkphp dwz 三级联动下拉菜单

本文详细介绍了如何在网页中实现三级联动下拉菜单的功能,包括前端页面展示和后端数据处理逻辑。

Tpl\ComBox\index.html:

<h2 class="contentTitle">下拉菜单</h2>

<div class="pageContent" layoutH="56">
	<select class="combox" name="province" ref="w_combox_city" refUrl="__URL__/returnCity/cityId/{value}">
		<option value="all">所有省市</option>
		<option value="bj">北京</option>
		<option value="sh">上海</option>
	</select>
	<select class="combox" name="city" id="w_combox_city" ref="w_combox_area" refUrl="__URL__/returnArea/areaId/{value}">
		<option value="all">所有城市</option>
	</select>
	<select class="combox" name="area" id="w_combox_area">
		<option value="all">所有区县</option>
	</select>
</div>

Action\ComBoxAction.class.php:

<?php
// 三级联动下拉菜单
class ComBoxAction extends CommonAction {    
     
    public function returnCity(){
        $cityId = $_REQUEST['cityId'];
        if($cityId=='sh'){
            $arrCity = array(array('all','所有城市'),array('sh','上海市'));
        }else if($cityId=='bj'){
            $arrCity = array(array('all','所有城市'),array('bj','北京市'));
        }else{
            $arrCity = array(array('all','所有城市'));
        }
         echo json_encode($arrCity);
    }
    
    public function returnArea(){
        $areaId = $_REQUEST['areaId'];
        if($areaId=='sh'){
            $arrArea = array(array('1','上海城市1'),array('2','上海城市2'));
        }else if($areaId=='bj'){
            $arrArea = array(array('3','北京城市3'),array('bj','北京城市4'));
        }else{
            $arrArea = array(array('all','所有城市'));
        }
        
         echo json_encode($arrArea);
    }
    
}
?>


PHP代码 <?php namespace Admin\Controller; use Think\Controller; class GoodController extends Controller { public function release() { /* * 开始新的操作 * */ $data=array(); $data['productname']=$_POST['productname']; $data['introduction']=$_POST['introduction']; $data['codenumber']=$_POST['codenumber']; $data['Productunit']=I('post.Productunit'); $data['sku']=I('post.sku'); $data['province']=I('post.province'); $data['city']=I('post.city'); $data['town']=I('post.town'); $data['classification']=I('post.classification'); $data['Extendedclass']=I('post.Extendedclass'); $data['Commoditybrand']=I('post.Commoditybrand'); $data['Commoditybrand']=I('post.Commoditybrand'); $data['Shopprice']=I('post.Shopprice'); $data['Marketvalue']=I('post.Marketvalue'); $data['Capitalizedcost']=I('post.Capitalizedcost'); $data['Commission']=I('post.Commission'); $data['original_img']=I('post.original_img'); /*商品重量*/ $data['Commodityweight']=I('post.Commodityweight'); $data['mail']=I('post.mail'); /*库存数量*/ $data['Inventoryquantity']=I('post.Inventoryquantity'); /*赠送积分*/ $data['Giftpoints']=I('post.Giftpoints'); /*兑换积分*/ $data['exchange_integral']=I('post.exchange_integral'); /*商品关检词*/ $data['Keyword']=I('post.Keyword'); /*商品详情描述*/ $data['describe']=I('post.describe'); $commodity=M('commodity'); /*准备开启事物*/ $commodity->startTrans(); $result=$commodity->add($data); if(!$result){ /*回滚事物*/ $commodity->rollback(); }else{ /*提交事物*/ $commodity->commit(); } /*1导入thinkphp得我自带的auth类库 * 加锁操作。若果同个用户(判断同个用户名操作)同时加入同样的sku时, * 那么如果存在时就加不上去(数量),如果不存在时(如果不存在时的数量不一样时)就insert上去 * */ $province = M('prvices')->where ( array('pid'=>1) )->select (); $this->assign('province',$province); $this->display(); } public function getRegion(){ /* * 接收市区 * */ $Region=M("prvices"); $map['pid']=$_REQUEST["pid"]; $map['type']=$_REQUEST["type"]; $list=$Region->where($map)->select(); echo json_encode($list); } public function sku() { $this->display(); } } html: <tr> <td>商品所在地</td> <td> <select name="addres" id="province" <option value="0" selected>省份/直辖市</option> <volist name="province" id="vo"> <option value="{$vo.id}" >{$vo.name} </option> </volist> </select> <select name="city" id="city" <option value="0">市/县</option> </select> <select name="town" id="town"> <option value="0">镇/区</option> </select> </td> </tr> function loadRegion(sel,type_id,selName,url){ jQuery("#"+selName+" option").each(function(){ jQuery(this).remove(); }); jQuery("<option value=0>请选择</option>").appendTo(jQuery("#"+selName)); if(jQuery("#"+sel).val()==0){ return; } jQuery.getJSON(url,{pid:jQuery("#"+sel).val(),type:type_id}, function(data){ if(data){ jQuery.each(data,function(idx,item){ jQuery("<option value="+item.id+">"+item.name+"</option>").appendTo(jQuery("#"+selName)); }); }else{ jQuery("<option value='0'>请选择</option>").appendTo(jQuery("#"+selName)); } } ); }
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值