dqj96395 2016-08-16 07:56
浏览 71
已采纳

html中的动态下拉列表

Im making a website for school and I needed a dynamic dropdown. I went about making it using this tutorial tutorial.

I have finished the first 6 parts and everything worked. In the last part when the first dropdown should appear it just doesn't. If the question is hard to answer or could have more answers just tell me what comes to mind and ill check. Ty in advance.

<html>
<head>
    <title>askldfjdasklf</title>
    <meta charset="UTF-8">
    <meta name "viewport" content="width=device-width">
</head>
<body>

    <label>Starost</label>
    <select id="starost"></select><br>
    <label>Praznuje</label>
    <select id="praznuje"></select><br>

    <script src="jquery-3.1.0.min.js"></script>
    <script src="script.js"></script>
</body>

<pre>$(document).ready(function ()
{
    $.getJSON("get_starost.php", success = function(data)
    {
        var options = "";

        for (var i 0; i < data.length; i++)
        {
            options += "<option value='" + data[i].toLowerCase() + "'>" + data[i] + "</option>";
        }
        $("#starost").append(options);

    }); 
});
</pre>

<pre>
<?php 
    require "opendb.php";

    $query = "SELECT starost FROM filter_starost";
    $data = mysql_query($query, $conn);

    $starost = array();

    while ($row = mysql_fetch_array($data))
    {
        array_push($starost, $row["starost"]);
    }
    echo json_encode($starost);

    require "closedb.php";
?>
</pre>
  • 写回答

2条回答 默认 最新

  • douhuan1908 2016-08-16 08:00
    关注

    You are missing = i 0in you for loop

    for (var i = 0; i < data.length; i++)
    { 
    
    }
    

    and open web browser console to check errors and for debug. This will help you a lot.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画