JSON-使JSON结果显示在页面上

用户名

我目前正在制作一个简单的Web应用程序,其中涉及用户将分数预测输入到本地存储。该应用程序的一项功能是使用JSON检索我所做的虚拟足球得分。

但是,当我单击“显示灯具”按钮时,结果最终将发布在空白屏幕上,并且它们不会显示在我的样式HTML文件中。

有人可以让我知道如何将结果显示在页面上吗?

这是我的html文件。

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>Premier League Site</title>
    <link rel="stylesheet" href="style.css"/>
</head>
<body>
<script src="elliot.js"></script>

    <div id="wrapper">
    <header id="header">
    <h1>Premier League Site</h1>
    </header>

    <nav id ="Menu_Bar">
    <ul>
        <li>Home</li>
        <li>Teams</li>
        <li>Extras</li>
    </ul>

    </nav>

    <section id="fixtures">

<input type="button" id="fixtures" value="Show Fixtures" onclick="fixtures()">

    </section>

    <section id="sectionone">
    What is the score for Game one?
        <form>
            <p>Home: <input type="number" id="one"></p>
            <p>Away: <input type="number" id="two"></p>
            <p><input type="button" id="button" value="Save"></p>
            <p><input type="button" id="dbutton" value="Delete" onclick="deleteKey()"></p>
            <p><input type="button" id="clear" value="Clear All" onclick="clearAll();" ></p>
        </form>
    </section>
    <section id="sectiontwo">
        Stored Info should go here
    </section>  
    <section id="sectionthree">
    What is the score for Game two?
        <form>
            <p>Home: <input type="number" id="three"></p>
            <p>Away: <input type="number" id="four"></p>
            <p><input type="button" id="buttontwo" value="Save"></p>
            <p><input type="button" id="dbuttontwo" value="Delete" onclick="deleteKeytwo()"></p>
            <p><input type="button" id="cleartwo" value="Clear All" onclick="clearAlltwo();" ></p>
        </form>     
    </section>
    <section id="sectionfour">
        Stored Info should go here
    </section>
<section id="sectionfive">
    What is the score for Game three?
        <form>
            <p>Home: <input type="number" id="five"></p>
            <p>Away: <input type="number" id="six"></p>
            <p><input type="button" id="buttonthree" value="Save"></p>
            <p><input type="button" id="dbuttonthree" value="Delete" onclick="deleteKeythree()"></p>
            <p><input type="button" id="clearthree" value="Clear All" onclick="clearAllthree();" ></p>
        </form>     
    </section>
    <section id="sectionsix">
        Stored Info should go here
    </section>  
<section id="sectionseven">
    What is the score for Game four?
        <form>
            <p>Home: <input type="number" id="seven"></p>
            <p>Away: <input type="number" id="eight"></p>
            <p><input type="button" id="buttonfour" value="Save"></p>
            <p><input type="button" id="dbuttonfour" value="Delete" onclick="deleteKeyfour()"></p>
            <p><input type="button" id="clearfour" value="Clear All" onclick="clearAllfour();" ></p>
        </form>     
    </section>
    <section id="sectioneight">
        Stored Info should go here
    </section>      
    <section id="sectionnine">
    What is the score for Game five?
        <form>
            <p>Home: <input type="number" id="nine"></p>
            <p>Away: <input type="number" id="ten"></p>
            <p><input type="button" id="buttonfive" value="Save"></p>
            <p><input type="button" id="dbuttonfive" value="Delete" onclick="deleteKeyfive()"></p>
            <p><input type="button" id="clearfive" value="Clear All" onclick="clearAllfive();" ></p>
        </form>     
    </section>
    <section id="sectionten">
        Stored Info should go here
    </section>  
    <section id="sectioneleven">
    What is the score for Game six?
        <form>
            <p>Home: <input type="number" id="eleven"></p>
            <p>Away: <input type="number" id="twelve"></p>
            <p><input type="button" id="buttonsix" value="Save"></p>
            <p><input type="button" id="dbuttonsix" value="Delete" onclick="deleteKeysix()"></p>
            <p><input type="button" id="clearsix" value="Clear All" onclick="clearAllsix();" ></p>
        </form>     
    </section>
    <section id="sectiontwelve">
        Stored Info should go here
    </section>  
    <section id="sectionthirteen">
    What is the score for Game seven?
        <form>
            <p>Home: <input type="number" id="thirteen"></p>
            <p>Away: <input type="number" id="fourteen"></p>
            <p><input type="button" id="buttonseven" value="Save"></p>
            <p><input type="button" id="dbuttonseven" value="Delete" onclick="deleteKeyseven()"></p>
            <p><input type="button" id="clearseven" value="Clear All" onclick="clearAllseven();" ></p>
        </form>     
    </section>
    <section id="sectionfourteen">
        Stored Info should go here
    </section>  
    <section id="sectionfifteen">
    What is the score for Game eight?
        <form>
            <p>Home: <input type="number" id="fifteen"></p>
            <p>Away: <input type="number" id="sixteen"></p>
            <p><input type="button" id="buttoneight" value="Save"></p>
            <p><input type="button" id="dbuttoneight" value="Delete" onclick="deleteKeyeight()"></p>
            <p><input type="button" id="cleareight" value="Clear All" onclick="clearAlleight();" ></p>
        </form>     
    </section>
    <section id="sectionsixteen">
        Stored Info should go here
    </section>  
    <section id="sectionseventeen">
    What is the score for Game nine?
        <form>
            <p>Home: <input type="number" id="seventeen"></p>
            <p>Away: <input type="number" id="eighteen"></p>
            <p><input type="button" id="buttonnine" value="Save"></p>
            <p><input type="button" id="dbuttonnine" value="Delete" onclick="deleteKeynine()"></p>
            <p><input type="button" id="clearnine" value="Clear All" onclick="clearAllnine();" ></p>
        </form>     
    </section>
    <section id="sectioneighteen">
        Stored Info should go here
    </section>  
    <section id="sectionnineteen">
    What is the score for Game ten?
        <form>
            <p>Home: <input type="number" id="nineteen"></p>
            <p>Away: <input type="number" id="twenty"></p>
            <p><input type="button" id="buttonten" value="Save"></p>
            <p><input type="button" id="dbuttonten" value="Delete" onclick="deleteKeyten()"></p>
            <p><input type="button" id="clearten" value="Clear All" onclick="clearAllten();" ></p>
        </form>     
    </section>
    <section id="sectiontwenty">
        Stored Info should go here
    </section>
    <body onload="drawCanvas();">
    <div>
        <canvas id="myCanvas" width="540" height="200">
            <p>Your browser doesn't support canvas.</p>
        </canvas>
    </div>
</body>

<script>
var surface;
var footy;
var x = 50;
var y = 0;
var dirX = 3;
var dirY = 3;

function drawCanvas() {
    // Get our Canvas element
    surface = document.getElementById("myCanvas");

    if (surface.getContext) {
        // If Canvas is supported, load the image
        footy = new Image();
        footy.onload = loadingComplete;
        footy.src = "football.png";
    }
}

function loadingComplete(e) {
    // When the image has loaded begin the loop
    setInterval(loop, 25);
}

function loop() {
    // Each loop we move the image by altering its x/y position

    // Grab the context
    var surfaceContext = surface.getContext('2d');

    // Clear the canvas to White
    surfaceContext.fillStyle = "rgb(255,255,255)";
    surfaceContext.fillRect(0, 0, surface.width, surface.height);

    // Draw the image
    surfaceContext.drawImage(footy, x, y);

    x += dirX;
    y += dirY;

    if (x <= 0 || x > 540 - 50) {
        dirX = -dirX;
    }
    if (y <= 0 || y > 200 - 50) {
        dirY = -dirY;
    }
}
</script>   
    <footer id="footer">
        Elliot Harrison 2014
    </footer>
    </div>
</body>
</html>

这是我的Javascript文件中的装置代码。

function fixtures(){

var obj1 = {Game: "Game One", Home:"Arsenal", Away:"Norwich"};
var obj2 = {Game: "Game Two", Home:"Cardiff", Away:"Aston Villa"};
var obj3 = {Game: "Game Three", Home:"Crystal Palace", Away:"Chelsea"};
var obj4 = {Game: "Game Four", Home:"Manchester United", Away:"Newcastle United"};
var obj5 = {Game: "Game Five", Home:"Fulham", Away:"Hull City"};
var obj6 = {Game: "Game Six", Home:"Swansea", Away:"Manchester City"};
var obj7 = {Game: "Game Seven", Home:"Sunderland", Away:"Stoke"};
var obj8 = {Game: "Game Eight", Home:"West Bromwich Albion", Away:"Everton"};
var obj9 = {Game: "Game Nine", Home:"Southampton", Away:"West Ham United"};
var obj10 = {Game: "Game Ten", Home:"Tottenham Hotspurs", Away:"Liverpool"};

document.write(obj1.Game+" - "+obj1.Home+" Vs "+obj1.Away);
document.write("</br>")
document.write(obj2.Game+" - "+obj2.Home+" Vs "+obj2.Away);
document.write("</br>")
document.write(obj3.Game+" - "+obj3.Home+" Vs "+obj3.Away);
document.write("</br>")
document.write(obj4.Game+" - "+obj4.Home+" Vs "+obj4.Away);
document.write("</br>")
document.write(obj5.Game+" - "+obj5.Home+" Vs "+obj5.Away);
document.write("</br>")
document.write(obj6.Game+" - "+obj6.Home+" Vs "+obj6.Away);
document.write("</br>")
document.write(obj7.Game+" - "+obj7.Home+" Vs "+obj7.Away);
document.write("</br>")
document.write(obj8.Game+" - "+obj8.Home+" Vs "+obj8.Away);
document.write("</br>")
document.write(obj9.Game+" - "+obj9.Home+" Vs "+obj9.Away);
document.write("</br>")
document.write(obj10.Game+" - "+obj10.Home+" Vs "+obj10.Away);
document.write("</br>")
}

谢谢你们。

奥列格

您必须生成html代码,然后将其插入到容器中。

首先,创建容器<div id="container"></div>

然后生成html代码:

var html = '';
html += obj1.Game+' - '+obj1.Home+' Vs '+obj1.Away + '<br />';
html += obj2.Game+' - '+obj2.Home+' Vs '+obj2.Away + '<br />';
html += obj3.Game+' - '+obj3.Home+' Vs '+obj3.Away + '<br />';
...

最后插入代码:

document.getElementById('container').innerHTML = html;

PS而且您body的页面上应该只有一个标签。卸下第二个,然后插入onload="drawCanvas();"第一个。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在页面上显示JSON?

来自分类Dev

无法在页面上显示JSON

来自分类Dev

如何在JSON页面上显示JSON对象列表

来自分类Dev

如何在HTML页面上显示JSON文件

来自分类Dev

获取某些 json 值并显示在 html 页面上

来自分类Dev

在页面上保存/加载 JSON

来自分类Dev

如何在新页面中显示JSON结果?

来自分类Dev

搜索 JSON 并在 HTML 页面中显示结果

来自分类Dev

Ionic2 / Angular2:在查询页面上显示JSON响应时出错

来自分类Dev

如何使用Angular.js在页面上显示从JSON检索的图像

来自分类Dev

在JSON对象的html页面上的列表视图中显示图像和描述

来自分类Dev

使用Flask在新页面上将HTML表单数据显示为JSON

来自分类Dev

在ajax中(从json php文件)调用时,无法获取obj属性以显示在html页面上

来自分类Dev

如何基于Node JS发送的JSON数据在HTML页面上显示图表

来自分类Dev

如何将JSON数据存储在数组中,然后将其显示在HTML页面上

来自分类Dev

Ionic2 / Angular2:在查询页面上显示JSON响应时出错

来自分类Dev

如何在 HTML 页面上使用 JQuery 显示来自 json 文件的图像?

来自分类Dev

如何在函数级别获取 JSON 并在 Angular2 中的 HTML 页面上显示

来自分类Dev

如何根据字符串值在页面上显示或隐藏 JSON 数据?

来自分类Dev

在Python中显示JSON特定的JSON结果

来自分类Dev

显示来自 Json 结果的数据

来自分类Dev

返回JSON列表并在MVC 4视图页面上使用

来自分类Dev

原始json没有出现在页面上

来自分类Dev

将URL解析为HTML页面上的可读json格式?

来自分类Dev

如何使用javascript单击页面上的json超链接

来自分类Dev

Android Studio:如何在HTTPS页面上获取JSON文件

来自分类Dev

如何在 HTML 页面上提取 JSON 数据

来自分类Dev

如何使用php计算不同json页面上的属性值

来自分类Dev

PHP + JSON显示结果没有键?

Related 相关文章

  1. 1

    在页面上显示JSON?

  2. 2

    无法在页面上显示JSON

  3. 3

    如何在JSON页面上显示JSON对象列表

  4. 4

    如何在HTML页面上显示JSON文件

  5. 5

    获取某些 json 值并显示在 html 页面上

  6. 6

    在页面上保存/加载 JSON

  7. 7

    如何在新页面中显示JSON结果?

  8. 8

    搜索 JSON 并在 HTML 页面中显示结果

  9. 9

    Ionic2 / Angular2:在查询页面上显示JSON响应时出错

  10. 10

    如何使用Angular.js在页面上显示从JSON检索的图像

  11. 11

    在JSON对象的html页面上的列表视图中显示图像和描述

  12. 12

    使用Flask在新页面上将HTML表单数据显示为JSON

  13. 13

    在ajax中(从json php文件)调用时,无法获取obj属性以显示在html页面上

  14. 14

    如何基于Node JS发送的JSON数据在HTML页面上显示图表

  15. 15

    如何将JSON数据存储在数组中,然后将其显示在HTML页面上

  16. 16

    Ionic2 / Angular2:在查询页面上显示JSON响应时出错

  17. 17

    如何在 HTML 页面上使用 JQuery 显示来自 json 文件的图像?

  18. 18

    如何在函数级别获取 JSON 并在 Angular2 中的 HTML 页面上显示

  19. 19

    如何根据字符串值在页面上显示或隐藏 JSON 数据?

  20. 20

    在Python中显示JSON特定的JSON结果

  21. 21

    显示来自 Json 结果的数据

  22. 22

    返回JSON列表并在MVC 4视图页面上使用

  23. 23

    原始json没有出现在页面上

  24. 24

    将URL解析为HTML页面上的可读json格式?

  25. 25

    如何使用javascript单击页面上的json超链接

  26. 26

    Android Studio:如何在HTTPS页面上获取JSON文件

  27. 27

    如何在 HTML 页面上提取 JSON 数据

  28. 28

    如何使用php计算不同json页面上的属性值

  29. 29

    PHP + JSON显示结果没有键?

热门标签

归档