Javascript 我能';在我的代码中找不到我的错误。总估计数为';t显示
这段代码是由Sasha Vodnik和Dan Gosselin编写的JavaScript第2章-第六版 我不明白为什么我的估计没有显示在旁边。我与教授给我们的版本进行了比较,我找不到导致估算结果无法显示的错误。有人知道我的错误是什么吗Javascript 我能';在我的代码中找不到我的错误。总估计数为';t显示,javascript,Javascript,这段代码是由Sasha Vodnik和Dan Gosselin编写的JavaScript第2章-第六版 我不明白为什么我的估计没有显示在旁边。我与教授给我们的版本进行了比较,我找不到导致估算结果无法显示的错误。有人知道我的错误是什么吗 <!DOCTYPE html> <html> <head> <!-- JavaScript 6th Edition Chapter 2 Chapter case Fan Trick Fine
<!DOCTYPE html>
<html>
<head>
<!--
JavaScript 6th Edition
Chapter 2
Chapter case
Fan Trick Fine Art Photography
Estimate web page
Author:
Date: September 23, 2015
Filename: estimate.htm
-->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Fan Trick Fine Art Photography - Estimate</title>
<link rel="stylesheet" media="screen and (max-device-width: 999px)href="fthand.css" />
<link rel="stylesheet" media="screen and (min-device-width: 1000px)"href="fantrick.css" />
<!--[if lt IE 9]>
<link rel="stylesheet" href="ftie.css" />
<![endif]-->
<link href='http://fonts.googleapis.com/css?family=Mr+Bedfort' rel='stylesheet' type='text/css'>
<script src="modernizr.custom.05819.js"></script>
</head>
<body>
<div id="container">
<header>
<h1>
<img src="images/ftlogo.png" alt="Fan Trick Fine Art Photography" title="" />
</h1>
</header>
<nav>
<ul>
<li><a href="#">About</a></li>
<li><a href="#">Portfolio</a></li>
<li id="currentpage"><a href="#">Estimate</a></li>
<li><a href="digital.htm">Digital 101</a></li>
</ul>
</nav>
<article>
<h2>Estimate</h2>
<p>Our experienced, professional photography team is available to capture memories of your wedding, celebration, or other special event.</p>
<p>Choose the custom options that fit your needs:</p>
<form id="estimateform">
<fieldset>
<legend><span>Photography</span></legend>
<input type="number" min="0" max="4" id="photognum" value="1" />
<label for="photognum">
<p># of photographers (1‑4)</p>
<p>$100/hr</p>
</label>
<input type="number" min="2" id="photoghrs" value="2" />
<label for="photoghrs">
<p># of hours to photograph (minimum 2)</p>
</label>
<input type="checkbox" id="membook" />
<label for="membook">
<p>Memory book</p>
<p>$250</p>
</label>
<input type="checkbox" id="reprodrights" />
<label for="reprodrights">
<p>Reproduction rights for all photos</p>
<p>$1250</p>
</label>
</fieldset>
<fieldset>
<legend><span>Travel</span></legend>
<input type="number" id="distance" value="0" />
<label for="distance">
<p>Event distance from Austin, TX</p>
<p>$1/mi per photographer</p>
</label>
</fieldset>
</form>
</article>
<aside>
<p>Total Estimate: <span id="estimate"></span></p>
</aside>
<footer>
<p>Fan Trick Fine Art Photography • Austin, Texas</p>
</footer>
</div>
<script src="ft.js"></script>
</body>
</html>
控制台日志会告诉你的
这只是粗略的一瞥所以我知道已经过去五年了,你可能已经不在乎了,但对于其他任何遇到这种情况的人来说。。。我找到了解决办法。(关于:JavaScript,由Sasha Vodnik和Don Gosselin撰写,第6版-第2章,教程问题) 书中所写的代码。。。(如果按照分步说明操作)它不会调用createEventListeners()函数 (可能是吗?可能是我错过了?可能我看不懂。我会再看一遍,但我非常确定对createEventListeners函数的唯一调用是在resetForm()函数中。) 我在页面底部添加了一个函数调用,现在估计值显示工作正常
createEventListeners()
我假设ft.js
是您的脚本,并且该脚本块不只是包含在HTML文件的末尾?resetForm()甚至从不触发。
function resetForm() {
document.getElementById("photogum").value = 1;
// ^^^^^^^^ doesn't exist should be
document.getElementById("photognum").value = 1;