当前位置: 首页 > 工具软件 > Spry > 使用案例 >

php--spry框架制作级联下拉菜单

谭晓博
2023-12-01

t78.php

<?php
header('Content-Type:text/xml');
?>

<root>
    <father id="1">
        <name>zhang san</name>
    </father>
    <father id="2">
        <name>li si</name>
    </father>
    <father id="3">
        <name>wang wu</name>
    </father>
</root>



t79.php

<?php
header('Content-Type:text/xml');
?>

<root>
    <?php if($_REQUEST['father_id'] == 1):?>
    <child>
        <name>zhang san xiao</name>
    </child>
    <child>
        <name>zhang san da</name>
    </child>
    <?php elseif($_REQUEST['father_id'] == 2):?>
    <child>
        <name>li si xiao</name>
    </child>
    <child>
        <name>li si da</name>
    </child>
    <child>
        <name>li si ping</name>
    </child>
    <child>
        <name>li si lan</name>
    </child>
    <?php elseif($_REQUEST['father_id'] == 3):?>
    <child>
        <name>wang wu xiao</name>
    </child>
    <child>
        <name>wang wu da</name>
    </child>
    <?php endif;?>
</root>

t80.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:spry="http://ns.adobe.com/spry">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>shi yong spry zhi zuo ji lian xia la cai dan</title>
    //引入spry框架
    <script type="text/javascript" src="Spry_1_6/includes/xpath.js"></script>
    //引入数据集
    <script type="text/javascript" src="Spry_1_6/includes/SpryData.js"></script>
    //脚本
    <script type="text/javascript">
        var dataset_father = new Spry.Data.XMLDataSet("t78.php","root/father");
        var dataset_child = new Spry.Data.XMLDataSet("t79.php","root/child");
        //加载child
        function re_load()
        {
            var father_id = document.getElementById('father').value;
            dataset_child.setURL("t79.php?father_id="+father_id);
            dataset_child.loadData();
            return false;
        }
    </script>
    <style type="text/css">
        body,td,th,select
        {
            font-family: Arial,Helvetica,sans-serif;
            font-size: 14px;
        }
    </style>
</head>
<body>
    <span>ji lian xia la cai dan</span>
    <hr>
    //father的数据区域
    <span spry:region="dataset_father">
        //状态
        <span spry:state="loading">shu ju jia zai zhong...</span>
        <span spry:state="failed">shu ju jia zai cuo wu!</span>
        <span spry:state="ready">
            father:
            <select name="father" id="father" onchange="re_load()">
                <option value="" selected="selected">qing xuan ze</option>
                //绑定数据
                <option value="{@id}" spry:repeat="dataset_father">{name}</option>
            </select>
        </span>
    </span>
    //child的数据区域
    <span spry:region="dataset_child">
        //状态
        <span spry:state="loading">shu ju jia zai zhong...</span>
        <span spry:state="failed">shu ju jia zai cuo wu!</span>
        <span spry:state="ready">
            child:
            <select name="child" id="child">
                <option value="" selected="selected">qing xuan ze</option>
                //绑定数据
                <option value="{name}" spry:repeat="dataset_child">{name}</option>
            </select>
        </span>
    </span>
</body>
</html>

 

 类似资料: