【问题标题】:Drop down menu using .load; JavaScript using PHP generated Drop down issues使用 .load 的下拉菜单; JavaScript 使用 PHP 生成的下拉问题
【发布时间】:2013-08-31 01:06:03
【问题描述】:

我正在尝试创建一个下拉菜单,该菜单由我的 RPi 目录的 PHP 列表创建,然后我可以选择一个条目并使用 .load() 功能在我的 siteDev 上显示选定的 HTML 文件内容.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>

【问题讨论】:

    标签: php javascript jquery


    【解决方案1】:

    更改以下功能。此函数中缺少附加“+”

    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');
    }
    

    【讨论】:

    • 糟糕,错过了。然而,警报现在只是告诉变量被列为未定义:/
    • 在函数 udLoad 中,给 var value = sel,因为在 select onchange 中您传递的是参数,因为 this.value 将传递值
    猜你喜欢
    • 2016-05-08
    • 1970-01-01
    • 1970-01-01
    • 2012-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    • 1970-01-01
    相关资源
    最近更新 更多