<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>下拉框</title>
<link rel="stylesheet" href="<?= RESOURCES ?>/SelectMenu/selectmenu.css" type="text/css">
<script src="<?= RESOURCES ?>/js/jquery.js"></script>
<script src="<?= RESOURCES ?>/js/area.js"></script>
</head>
<body>
<div style="float: left; width:30%" >
	  <select style="width:30%" id="DropDownList1"></select>
      <select style="width:30%" id="DropDownList2"></select>
      <select style="width:33%" id="DropDownList3"></select>
      <input type="hidden" name="suozaidiqu" id="suozaidiqu" value="" />
</div>
 




</body>

<script type="text/javascript">

var s = ["DropDownList1", "DropDownList2", "DropDownList3"]; //三个select的name
var opt0 = ["", "", ""]; //初始值

// 如果有默认值 第一个参数是默认值，
// 第二个参数是默认值以什么分割 默认为一个空格
function _init_area(def, spstr) {  //初始化函数
    for (i = 0; i < s.length - 1; i++) {
        document.getElementById(s[i]).onchange = new Function("change(" + (i + 1) + ")");
    }
    if (def != null && def.length > 0) {
        if (spstr == null || spstr.length < 1) { spstr = ' '; }
        var areadata = def.split(spstr);
        if (def.length > 0) {
            for (var areai = 0; areai < areadata.length; areai++) {
                change(areai);
                document.getElementById(s[areai]).value = areadata[areai];
            }
        }
    } else {
        change(0);
    }
}


function edit_address() {
    var t1 = "";
    var list = document.getElementById("DropDownList1");
    for (var i = 0; i < list.options.length; i++) {
        if (list.options[i].selected) {
            t1 = list.options[i].value;
        }
    }

    var t2 = "";
    var list = document.getElementById("DropDownList2");
    for (var i = 0; i < list.options.length; i++) {
        if (list.options[i].selected) {
            t2 = list.options[i].value;
        }
    }
    
    var t3 = "";
    var list = document.getElementById("DropDownList3");
    for (var i = 0; i < list.options.length; i++) {
        if (list.options[i].selected) {
            t3 = list.options[i].value;
        }
    }
   
    //获取父框架的元素
    var _ghyOb1=$('#<?php echo $_GET["field"]?>', window.parent.document);
    _ghyOb1.val( t1 + "-" + t2 + "-" + t3);

}

_init_area("", "-");

//获取父框架的元素的默认值
var _ghyOb=$('#<?php echo $_GET["field"]?>', window.parent.document);
var selectValue="";

if(_ghyOb.val().trim()!="")
{
	selectValue=_ghyOb.val().trim();
	var selectValueArray=selectValue.split('-');
	if (typeof(selectValueArray[0]) != "undefined" && selectValueArray[0]!="" ){ 
		console.log("selectValueArray[0]"+"  "+selectValueArray[0]);
		$("#DropDownList1").val(selectValueArray[0]);
	}
	if (typeof(selectValueArray[1]) != "undefined" && selectValueArray[1]!="" ){ 
		console.log("selectValueArray[1]"+"  "+selectValueArray[1]);
		change(1);
		$("#DropDownList2").val(selectValueArray[1]);
	}
	if (typeof(selectValueArray[2]) != "undefined" && selectValueArray[2]!="" ){ 
		console.log("selectValueArray[2]"+"  "+selectValueArray[2]);
		change(2);
		$("#DropDownList3").val(selectValueArray[2]);
	}
	
	
} 




$('#DropDownList1').change(function(){ 
	edit_address();
})

$('#DropDownList2').change(function(){ 
	edit_address();
})

$('#DropDownList3').change(function(){ 
	edit_address();
})
 
</script>

</html>
