自动获取“省-市-县-乡镇”地址 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

未完待续。

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

随机文章:

1、5款纯div+css制作的弹出菜单(标准且无js)(三)
https://www.onexin.net/5-div-css-js/

2、Java入门学习addBatch()用法
https://www.onexin.net/java-entry-learning-addbatch-usage/

3、UCenter Home常用sql语句高级篇(二)
https://www.onexin.net/commonly-used-sql-statement-ucenter-home-advanced-articles/

4、Python 库中WebSocket使用示例
https://www.onexin.net/python-websocket/

5、Discuz!X站内开启视频播放代码
https://www.onexin.net/discuz-x-stations-open-video-player-code/

Leave a Reply