首页 > 开发 > PHP > 正文

给你一个JS实现列表连动的例子

2024-05-04 22:58:22
字体:
来源:转载
供稿:网友
<script language="javascript">
function show_board(board_top,board){
    var select_index,select_id,select_name,i,j;
    select_index=board_top.selectedindex;
    select_id=board_top.options[select_index].value;
    form1.parent_id.value=select_id;
    form1.board_top_add.value=board_top_arr[select_id].name;
    form1.note_top_add.value=board_top_arr[select_id].note;
    form1.manager_top_add.value=board_top_arr[select_id].manager;
    for(i=board.length-1;i>=0;i--){
        board.remove(i);
    }
    for(i=0;i<board_arr[select_id].length;i++){
        if(typeof(board_arr[select_id][i])=="object"){
            var ooption = document.createelement("option");
            ooption.text=board_arr[select_id][i].name;
            ooption.value=board_arr[select_id][i].id;
            //document.all.mylist.add(ooption);
            board.add(ooption);
        }
    }
    
}
function select_board(board){
    var select_index,select_id;
    select_index=board.selectedindex;
    select_id=board.options[select_index].value;
    form1.board_id.value=select_id;
    form1.board_add.value=board_arr[form1.parent_id.value][select_id].name;
    form1.note_add.value=board_arr[form1.parent_id.value][select_id].note;
    form1.manager_add.value=board_arr[form1.parent_id.value][select_id].manager;
}
function w(text){
    document.write(text);
}
function board_func(id,name,note,manager){
    this.id=id;
    this.name=name;
    this.note=note;
    this.manager=manager;
}
var board_arr=new array();
var board_top_arr=new array();
<?php
$board_top_option="";
$query="select board_id,board_name,board_note,board_manager from board where board_level='1' order by board_id";
$result_top=mysql_db_query($dbname,$query);
while($myrow_top=mysql_fetch_array($result_top)){
    $board_top_option.="<option value='$myrow_top[board_id]'>$myrow_top[board_name]</option>/n";
    echo "board_top_arr[$myrow_top][board_id]]=new board_func('$myrow_top[board_id]','$myrow_top[board_name]','$myrow_top[board_note]','$myrow_top[board_manager]');/n";
    $query="select board_id,board_name,board_note,board_manager from board where board_level='2' and parent_id='$myrow_top[board_id]' order by board_id";
    $result=mysql_db_query($dbname,$query);
    echo "var tmp_arr=new array();/n";
    while($myrow=mysql_fetch_array($result)){
        echo "tmp_arr[$myrow][board_id]]=new board_func('$myrow[board_id]','$myrow[board_name]','$myrow[board_note]','$myrow[board_manager]');/n";
    }
    echo "board_arr[$myrow_top][board_id]]=tmp_arr;/n";
}
?>

function checkform(text){
    if(text.value.length==0){
        alert("请输入要添加的版面名称!");
        return false;
    }
    return true;
}
</script>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表