日期:2014-05-16  浏览次数:20332 次

求懂JS的帮忙看看数组的格式问题
 <?php
$add_result = mysql_query("select * from hzl_type");
$add_result_num = mysql_num_rows($add_result);
echo '<script type="text/javascript">var name_array,parent_array,id_array;name_array=new Array

();parent_array=new Array();id_array=new Array();';
for($i = 0; $i < $add_result_num; $i++){
    mysql_data_seek($add_result,$i);
    $add_result_information = mysql_fetch_array($add_result);
    echo 'id_array['.$i.']='.$add_result_information['typeid'].';';
    echo 'name_array['.$i.']='.$add_result_information['typename'].';';
    echo 'parent_array['.$i.']='.$add_result_information['parentid'].';';
}
echo '</script>';
?>

<script type="text/javascript">
//*测试数据 没问题  但是上面数据库读出就有问题,没法载如三级联动 那个数组有什么问题吗
var id_array,name_array,parent_array;
id_array = new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,14);
name_array = new Array("湖北","广东","黄冈","武汉","东莞","虎门","浠水","蕲春","武昌","汉阳","东一","东

二","虎一","虎二");
parent_array = new Array(0,0,1,1,2,2,3,3,4,4,5,5,6,6);
 
/****三级版****/
function create_select(parent_id,sel_id,what_sel){
    var new_option;
    if(parent_id === ""){
        return;
    }
    if(what_sel == 1){
        document.getElementById("mid_sel").options.length = 0;
        document.getElementById("bot_sel").options.length = 0;
        new_option = new Option("请选择地区","");
        document.getElementById("mid_sel").options.add(new_option);
        new_option = new Option("请选择县市","");
        document.getElementById("bot_sel").options.add(new_option);
    }
    if(what_sel == 2){
        document.getElementById("bot_sel").options.length = 0;
        new_option = new Option("请选择县市","");
        document.getElementById("bot_sel").options.add(new_option);
    }
    for(var j = 0; j < id_array.length; j++){
        if(parent_array[j] == parent_id){
            new_option = new Option(name_array[j],id_array[j]);
            document.getElementById(sel_id).options.add(new_option);
        }
    }
}
/****无限级版****/
//获取上一级id
function get_top_id(the_id){
    for(var i = 0; i < id_array.length; i++){
        if(the_id == id_array[i]){
            return parent_array[i];
       &n