使用.load下拉菜单;使用PHP生成的JavaScript下拉问题

时间:2013-08-28 04:59:19

标签: php javascript jquery

我正在尝试创建一个下拉菜单,该菜单是由我的RPi目录的PHP列表创建的,然后我可以选择一个条目并使用.load()功能显示所选的HTML文件内容我的siteDev.php页面。
出现问题是我无法从我的下拉菜单中传回值,以允许我在#results div中显示内容。

<!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">

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>PHP and JS Notes</title>
        <!-- Style sheets, .dDown needs to be moved. .dDown
        {float: right} -->
        <style type="text/css">
</style>
        <link href="_resources/coverStyle.css" rel="stylesheet" type="text/css"
        />
        <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
        <!-- Loading external files via .load, hard coded 3 main files
        udLoad() will be used to select dated files e.g. 'us25082013.html' -->
        <script language="javascript" type="text/javascript">
            function jLoad0() {
                $('#result').load('devUpdates/devInProg.html #container');
            }
        </script>
        <script language="javascript" type="text/javascript">
            function udLoad(sel) {
                var value = sel.value;
                alert(value + ' page selected');
                $('#result').load('devUpdates/'
                value ' #container');
            }
        </script>
        <!-- This PHP loads the directory and lists the files below in
        the form. -->
        <?php if ($handle=o pendir( 'devUpdates')) { while (false !==( $file=r
        eaddir($handle))) { if (($file !="." ) && ($file !=".." )) { $thelist .='<option value="'
        .$file. '">'.$file. '</option>'; } } closedir($handle); } ?>
    </head>

    <body class="welcomeDiv">
        <form>
            <input type="button" name="pin" onclick="jLoad0()" value="Dev In Prog">
        </form>
        <!-- This is where the list of udxxxxxxxx.html files are listed. I want
        to take one of these and run them in a .load function. -->
        </br>
        </br>
        <form>
            <select name="dDown" class="dDown" id="dDown" onchange="udLoad(this.value)">
                <P>
                    <option value="">Select a page</option>
                </p>
                <P>
                    <?=$thelist?>
                </p>
            </select>
            <input type="submit" value="Go">
        </form>
        </br>
        </br>
        <div id="result"></div>
    </body>

</html>

1 个答案:

答案 0 :(得分:0)

更改以下功能。此功能中缺少追加“+”

function udLoad(sel){
    var value = sel.value;
    alert(value + ' page selected');
    $('#result').load('devUpdates/'value' #container');
}

function udLoad(sel){
    var value = sel;
    alert(value + ' page selected');
    $('#result').load('devUpdates/' + value +' #container');
}