easyui combobox三级联动

省、市、区的三级联动比较经典,而且问题还在于修改省,那么市、区要跟着变,修改市,则区跟着变。
下面的代码定义三个combobox

<tr>
				<td width="15%" style="text-align:right">注册区域:</td>
				<td width="85%" colspan="3">
					<input id="regProvince" name="regProvince" class="easyui-combobox" style="width:120px;"  data-options="required:true, editable:false,prompt: '请选择省份',missingMessage:'请选择省份'"  value="${oimSupplier.regProvince}" />
					<input id="regCity" name="regCity" class="easyui-combobox" style="width:120px;"  data-options="required:true, editable:false,prompt: '请选择城市',missingMessage:'请选择城市'"  value="${oimSupplier.regCity}" />
					<input id="regDistrict" name="regDistrict" class="easyui-combobox" style="width:120px;"  data-options="required:true, editable:false,prompt: '请选择区县',missingMessage:'请选择区县'"  value="${oimSupplier.regDistrict}" />
				</td>
			</tr>

以下代码是是初始化方法

$(function() {
			initProvince();
			initCity('${oimSupplier.regProvince}');
			initDistrict('${oimSupplier.regCity}');
		});

初始化省,主要看onselect方法,针对城市要clear清空数据,还得setvalue为空字符串,这样市的placeholder才有效,而区还要加上loadData为空数组,清理掉区下拉所有选项,因为市改变了,但是你没有选市,所以区应该没有任何选项。直到你选了市

function initProvince(){
			$('#regProvince').combobox({
				method:'get',
				url:ccs_ctx+'ccs04/' + DICTIONARY_FIELD.ADMIN_REGION,
				valueField:'id',
				textField:'name',
				onSelect:function(record){
					initCity(record.id);
					$('#regCity').combobox('clear');
					$('#regCity').combobox('setValue','');
					$('#regDistrict').combobox('clear');
					$('#regDistrict').combobox('setValue','');
					$('#regDistrict').combobox('loadData',[]);
				}
			});
		}
function initCity(pid){
			if ($.string.isNullOrEmpty(pid)){
				pid = -1;
			}
			$('#regCity').combobox({
				method:'get',
				url:ccs_ctx+'ccs04/' + DICTIONARY_FIELD.ADMIN_REGION +'?pid='+pid,
				valueField:'id',
				textField:'name',
				onSelect:function(record){
					initDistrict(record.id);
					$('#regDistrict').combobox('clear');
					$('#regDistrict').combobox('setValue','');
				}
			});
		}
function initDistrict(pid){
			if ($.string.isNullOrEmpty(pid)){
				pid = -1;
			}
			$('#regDistrict').combobox({
				method:'get',
				url:ccs_ctx+'ccs04/' + DICTIONARY_FIELD.ADMIN_REGION +'?pid='+pid,
				valueField:'id',
				textField:'name',
			});
		}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

warrah

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值