帝国CMS 二级联动 基于optionTree插件

<?php
$pc=array();
$pc[1] = array ("陪游","私人陪游|商务陪游|交友陪游|异国陪游");
$pc[2] = array ("家政陪护","保姆|育婴|月嫂|奶妈|老人护理");
$pc[3] = array ("美容休闲医疗陪护","化妆师|美容师|私人医生|按摩师|沐足师");
$pc[4] = array ("陪伴运动健身","游泳|骑行|徒步|球类|健身");
$pc[5] = array ("技能辅导陪教","家教|舞蹈|音乐|武术|跆拳道|汽车陪练|心理辅导师");
$pc[6] = array ("陪伴办事","律师|房产经纪人|房产证办证员|贷款按揭员");
$pc[7] = array ("陪伴娱乐类","泡吧|唱K|喝酒|吹水|打麻将|下棋");
$pc[8] = array ("其他","开锁、修灯、修水龙头");

$line_no = (isset($_GET['id']) && is_numeric($_GET['id']) ? (int) $_GET['id'] : null);
if (is_null($line_no)) {
	$pro=array();
	for($i=1;$i<count($pc);$i++){
		$pro[$i] = $pc[$i][0];
		$ctiy_arr = $pc[$i][1];
	}
}else{
	$pro=array();
	if($line_no<=35 && $line_no >= 1){
		$ctiy = explode("|",$pc[$line_no][1]);
		for($ii=0;$ii<count($ctiy);$ii++){
			$pi = $line_no."00".$ii;
			$pro[$pi] = $ctiy[$ii];
		}		
	}
}
echo json_encode($pro); 
?>

 

<!-- 二级联动 后台THML -->
<input name="p1" type="hidden" id="p1" value="<?=$ecmsfirstpost==1?"":ehtmlspecialchars(stripSlashes($r[p1]))?>" size="">
<script type="text/javascript" src="/skin/peiyou/js/jquery.optionTree.js"></script>
<script type="text/javascript">
$(function() {
	var options = {
		empty_value: 'null',
		indexed: true,  // the data in tree is indexed by values (ids), not by labels
		on_each_change: '/skin/peiyou/js/ask_type.php', // this file will be called with 'id' parameter, JSON data must be returned
		choose: '',
		preselect: {"p1": ['1','1']},
		set_value_on: 'each'
	};
	
	$.getJSON('/skin/peiyou/js/ask_type.php', function(tree) { // initialize the tree by loading the file first
		$('input[name=p1]').optionTree(tree, options);
	});
	
$("form").submit(function(e){
	var pro1= $('#p1cn').val($('select[name=p1_] option:selected').text());    //省中文
	var city1= $('#p2cn').val($('select[name=p1__] option:selected').text()); //市中文
	var pro1= $('#p1').val($('select[name=p1_] option:selected').val());     //省ID
	var city1= $('#p2').val($('select[name=p1__] option:selected').val());  //市ID
});
	
});
</script>
<input name="p2" type="hidden" id="p2" value="<?=$ecmsfirstpost==1?"":ehtmlspecialchars(stripSlashes($r[p2]))?>" size="">
<input name="p1cn" type="hidden" id="p1cn" value="<?=$ecmsfirstpost==1?"":ehtmlspecialchars(stripSlashes($r[p1cn]))?>" size="">
<input name="p2cn" type="hidden" id="p2cn" value="<?=$ecmsfirstpost==1?"":ehtmlspecialchars(stripSlashes($r[p2cn]))?>" size="">


<!-- 二级联动 前台THML -->
<input name="p1" type="hidden" id="p1" value="<?=$ecmsfirstpost==1?"":ehtmlspecialchars(stripSlashes($r[p1]))?>" size="">
<script type="text/javascript" src="/skin/peiyou/js/jquery.optionTree.js"></script>
<script type="text/javascript">
$(function() {
	var options = {
		empty_value: 'null',
		indexed: true,  // the data in tree is indexed by values (ids), not by labels
		on_each_change: '/skin/peiyou/js/ask_type.php', // this file will be called with 'id' parameter, JSON data must be returned
		choose: '',
		preselect: {"p1": ['1','1']},
		set_value_on: 'each'
	};
	
	$.getJSON('/skin/peiyou/js/ask_type.php', function(tree) { // initialize the tree by loading the file first
		$('input[name=p1]').optionTree(tree, options);
	});
	
$("form").submit(function(e){
	var pro1= $('#p1cn').val($('select[name=p1_] option:selected').text());    //省中文
	var city1= $('#p2cn').val($('select[name=p1__] option:selected').text()); //市中文
	var pro1= $('#p1').val($('select[name=p1_] option:selected').val());     //省ID
	var city1= $('#p2').val($('select[name=p1__] option:selected').val());  //市ID
});
	
});
</script>
<input name="p2" type="hidden" id="p2" value="<?=$ecmsfirstpost==1?"":DoReqValue($mid,'p2',stripSlashes($r[p2]))?>" size="">
<input name="p1cn" type="hidden" id="p1cn" value="<?=$ecmsfirstpost==1?"":DoReqValue($mid,'p1cn',stripSlashes($r[p1cn]))?>" size="">
<input name="p2cn" type="hidden" id="p2cn" value="<?=$ecmsfirstpost==1?"":DoReqValue($mid,'p2cn',stripSlashes($r[p2cn]))?>" size="">

 

你可能感兴趣的:(帝国CMS 二级联动 基于optionTree插件)