自动获取“省-市-县-乡镇”地址 For UCH 2.0

以下方法根据discuz!x修改,可用于UCH

common_district.sql //来源DX
function_profile.php //来源DX

1、打开cp_profile.htm文件,

修改


2、打开script_common.js文件,添加:

function showdistrict(container, elems, totallevel, changelevel) {
	var getdid = function(elem) {
		var op = elem.options[elem.selectedIndex];
		return op['did'] || op.getAttribute('did') || '0';
	};
	var pid = changelevel >= 1 && elems[0] && $(elems[0]) ? getdid($(elems[0])) : 0;
	var cid = changelevel >= 2 && elems[1] && $(elems[1]) ? getdid($(elems[1])) : 0;
	var did = changelevel >= 3 && elems[2] && $(elems[2]) ? getdid($(elems[2])) : 0;
	var coid = changelevel >= 4 && elems[3] && $(elems[3]) ? getdid($(elems[3])) : 0;
	var url = "cp.php?ac=common&op=district&container="+container
		+"&province="+elems[0]+"&city="+elems[1]+"&district="+elems[2]+"&community="+elems[3]
		+"&pid="+pid + "&cid="+cid+"&did="+did+"&coid="+coid+'&level='+totallevel+'&handlekey='+container+'&inajax=1';
	ajaxget(url, container, '');
}

3、打开cp_common.php文件,最后}替换为

} elseif($op == 'district') {
	$showlevel = intval($_GET['level']);
	$showlevel = $showlevel >= 1 && $showlevel <= 4 ? $showlevel : 4;
	$values = array(intval($_GET['pid']), intval($_GET['cid']), intval($_GET['did']), intval($_GET['coid']));
	$elems = array();
	if($_GET['province']) {
		$elems = array($_GET['province'], $_GET['city'], $_GET['district'], $_GET['community']);
	}
	$container = $_GET['container'];
	include_once (S_ROOT.'./source/function_profile'.php);
	$html = showdistrict($values, $elems, $container, $showlevel);
}

4、打开cp_common.htm文件,最后


替换为:


$html

未完待续。

随机文章:

1、YouTube视频短网址插入Discuz!X播放
https://www.onexin.net/let-discuz-x-support-insert-youtube-video-short-url/

2、以图换字的几个方法及思路
https://www.onexin.net/figure-for-word-methods-and-ideas/

3、Php高手带路–问题汇总解答
https://www.onexin.net/php-expert-to-lead-the-way-the-problem-summary-answer/

4、Laravel 8.x 简体中文最新手册指南 – 安装
https://www.onexin.net/laravel-8-x-docs-installation/

5、结合firebug学习jQuery选择器(菜鸟成功记)
https://www.onexin.net/learning-jquery-selector-rookie-success-diary-combined-with-firebug/

转载请注明出处:https://www.onexin.net/automatically-selects-the-province-city-county-township-address/

Leave a Reply

Your email address will not be published. Required fields are marked *