gpt4 book ai didi

JavaScript 代码不打印消息

转载 作者:行者123 更新时间:2023-12-03 06:07:29 24 4
gpt4 key购买 nike

所以突然间我的代码在执行时不再打印任何内容,HTML 似乎正在工作,但是当单击计算按钮时什么也没有发生,(程序还远未完成,但需要首先解决计算按钮的问题) 。尝试找出语法错误和小错误,但我猜还剩下一些,因为它在添加 if 语句之前首先起作用。

<html>
<head>

<meta name="group" content="95">
<meta name="author" content="Carolina Svantesson">
<meta name="author" content="Viktoria Hamnér">
<title>Calendar</title>

</head>

<body>
<h1>Weekday Calculator</h1>

<form id="inputForm">
<table>
<tr>
<td>Year:</td>
<td><input type ="text" id="year" value="" size="4"></td>
</tr>

<tr>
<td>Month:</td>
<td><input type ="text" id="month" value="" size="2"></td>
</tr>

<tr>
<td>Day:</td>
<td><input type ="text" id="day" value="" size="2"></td>
</tr>

<td>&nbsp;</td>
<td><input type ="button" id="button" value="Calculate"
onclick="handleInput(this.form);"></td>
</tr>
</table>
</form>

<p id="output"></p>

<script language="Javascript">
function handleInput(form){
// var form = document.getElementById("inputForm");
try {
var strYear = form.year.value;
var strMonth = form.month.value;
var strDay = form.day.value;

var intYear = parseInt(strYear);
var intMonth = parseInt(strMonth);
var intDay = parseInt(strDay);

if (isNaN(intYear))
throw "Incorrect input, year is not a number. ";
if (intYear <0 || intYear>9999)
throw "Incorrect input, year is out of the expected range (0--9999).";

if (isNaN(intMonth))
throw "Incorrect input, Month is not a number. ";
if (intMonth <1 || intMonth >12)
throw "Incorrect input, Month is out of expected range(1--12).";

if (isNaN(intDay))
throw "Incorrect input, Day is not a number.";
if (intMonth == 1, 3, 5, 7, 8, 10, 12)
if (intDay <1|| intDay>31)
throw "Incorrect input, Day is out of expected range (1--31).";

if (intMonth == 4, 6, 9, 11)
if (intDay <1 || intDay>30)
throw "Incorrect input, Day is out of expected range(1--30)";

if (intMonth == 2)
if (intYear % 4== 0 && %100 !==0)
if (intDay <1|| intDay>29)
throw "Incorrect input, Day is out of expected range(1--29)";
if (intMonth == 2)
if (intYear %4 !==0)
if (intDay <1|| intDay >28)
throw "Incorrect input, Day is out of expected range ( 1--28)";

var output =" "+ intYear + " " + intMonth + " " + intDay +"är en...";
document.getElementById("output").innerHTML = output;

}
catch (error){
document.getElementById("output").innerHTML="ERROR: " +error;
}



</script>

</body>
</html>

最佳答案

有两件事

你有

if (intYear % 4== 0 && %100 !==0)

应该是这样的:

if (intYear % 4== 0 && intYear % 100 !==0)

您的代码中还需要结束 }

这里正在工作:http://codepen.io/nilestanner/pen/WGAdoB

关于JavaScript 代码不打印消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39471292/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com