一个文本文件(Footy.txt),其中包含以下数据:
Collingwood
Geelong
Hawthorn (这是几个球队的名称)
 
现在写一个PHP代码(可以用到javascript)来执行
以下内容:
(2.1)(10分)生成一个下拉框(内容要求从footy.txt文件中读取),
(2.2)(10分)当从下拉框中选中一个特定的球队的时候生成一个动态的textrarea(文本输入区)和显示出一行该球队说明
如图:可使用的函数提示
求这段的php代码

解决方案 »

  1.   

    <?php
    $handle = fopen('Footy.txt', 'r');
    $options = '';
    while ($line = fgets($handle))
    {
    $options .= "<option value=\"{$line}\">{$line}</option>";
    }
    print <<<EOT
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Content-Language" content="zh-cn" />
    </head>
    <body>
    <p>
    <select id="footy" onclick="reset_footy()">
    {$options}
    </select>
    </p>
    <p>
    <textarea id="desc"></textarea>
    </p>
    <script type="text/javascript">
    function reset_footy()
    {
    var desc = '';
    switch (document.getElementById('footy').value)
    {
    //I DONT KNOW WHAT YOU ARE GOING TO DO HERE.... 
    case '':
    break;
    }
    document.getElementById('desc').innerHTML = desc;
    }
    </script>
    </body>
    </html>
    EOT;