无法在HTML上显示JSON数据

问题描述 投票:2回答:1

我想在我的文件'question.json'中随机显示HTML中的数据,但不知为何什么都没有发生。我开始学习JavaScript,但还是不知道如何解决。下面是我的代码。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Answer Something</title>
    <script>
        $.getJSON('question.json', function(data){
            console.log(data)
            let questionList = data[Math.floor(Math.random()* data.length)];
            let display = document.getElementById('question');
            display.innerHTML = questionList;
        });
    </script>
</head>
<body>
    <nav>
        <a href="/ask">Quick Ask</a>
        <a href="/answers">Quick Answers</a>  
    </nav>
    <h1 id="question"></h1>
    <div>
        <button>Sai/Không/Trái</button>
        <button>Đúng/Có/Phải</button>
    </div><br>

    <div>
        <button>Kết quả vote</button>
        <button>Câu hỏi khác</button>
    </div>
</body>
</html>
javascript html json
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.