我正在建立一个网站,我已经完成了,但代码中有一个很大的错误。我创建了一个表格,其中有一个按钮,它是计算某个表达式并将计算结果显示在表格中的函数。计算发生但不显示在表格中。以下是我有:一个表格中的功能按钮
<!DOCTYPE html>
<html>
<!--DB 11/2/2015-->
<!-- W3 Schools was referenced in building this code-->
<head>
\t <meta charset="utf-8">
\t <title>Assignment 8</title> \t
\t <link href="images/avatar.png" rel="shortcut icon" type="image/png">
\t <link href="css/stylesheet.css" rel="stylesheet" type="text/css">
\t <script src="js/javascript.js" type="text/javascript"></script>
\t <style type="text/css">
\t </style>
\t
</head>
<body onload="fillitin()">
<header>
</header>
<aside>
</aside>
<div id="main">
\t \t
<h1> Assignment 8: Operators and Expression</h1>
<br>
<p id="demo"></p> \t
<script>
\t var d = new Date();
\t months = ['Janurary','Feburary','March','April','May','June','July','August','September','October','November','December']
\t var date = months[d.getMonth()]+" "+d.getDate()+" "+d.getFullYear();
\t
\t
document.getElementById("demo").innerHTML = date;
</script>
<h2 style="text-align:center"> S'mores!</h2>
<h4> CLick on the button serves to learn the amount of ingredients needed to make S'mores!</h4>
<table style="width:50%" border="1">
<form name="myform" method="">
<tr>
\t <td> <br>
\t \t <input type="text" id="num1" value="1">
\t </td>
\t <td>
\t \t <button onclick="myFunction()">Serves</button>
\t </td>
\t
</tr>
</form>
<tr>
\t <td id="M"></td>
\t <td>Large Marshmallows</td>
</tr>
<tr>
\t <td id="G"></td>
\t <td>Graham Cracker</td>
</tr>
<tr>
\t <td id="C"></td>
\t <td>Ounches Chocolate</td>
</tr>
</table>
<script>
\t function fillitin() {
\t document.getElementById("M").InnerHTML="1";
\t document.getElementById("G").InnerHTML="1";
\t document.getElementById("C").InnerHTML="1.5";
\t }
\t
\t function myFunction() {
\t var x=document.getElementById("num1").value;
\t document.getElementById("M").InnerHTML=x;
\t document.getElementById("G").InnerHTML=x;
\t document.getElementById("C").InnerHTML=x*1.5;
\t }
\t </script>
<ul>
<li>
Heat the marshmallow over an open flame until it begins to brown and melt.
</li>
<li>Break the graham cracker in half. Put the chocolate on one half of the cracker, and put the warm marshmallow on the other. </li>
<li>Enjoy! Don’t burn your mouth!</li>
</ul>
\t <img alt="picture of smores" height="129" src="images/picture1.jpg" width="194">
\t <cite> picture taking from <a href="http://www.instructables.com/id/no-campfire-smores/"> http://www.instructables.com/id/no-campfire-smores/
\t \t \t \t \t \t \t </a></cite>
\t </div>
<footer>
</footer>
</body>
</html>
您有一些错误,https://validator.w3.org/nu/会显示 – Quentin
* alt =“图片的smores”* - 去阅读http://www.alanflavell。 org.uk/alt/alt-text.html – Quentin
就像他们说的,将InnerHTML改为innerHTML。由于这是客户端计算,因此您不需要'form'标记。无论如何你的作品。 – alix