springboot怎么把数据传给前端:springboot 如何引入前端 bootstrap?
这种问题网上一搜一大堆,你可以具体找一篇文章试试,遇到问题可以针对相关问题去提问。springboot通过jar包方式引入bootstrap_个人文章 - SegmentFault 思否 这不是查查就
顺晟科技
2022-10-19 12:34:36
194
所以,我试图用JavaScript计算用户输入的两个日期之间的差异;但是,我不断收到invaliddate。如有任何帮助,不胜感激。
以下是我的代码:
<!DOCTYPE html>
<html>
<head>
<title>Assignment Calculator</title>
</head>
<body>
<h1>Assignment Calculator</h1>
<form>
<label for="StartDate">Date to Start:</label>
<input id="StartDate" name="StartDate" type="date"/>
<label for="DueDate">Due Date:</label>
<input id="DueDate" name="DueDate" type="date"/>
<input type="submit" value="Submit" onclick="displayDates()">
</form>
<script type = "text/javascript" >
// Get start date and due date
var startInput = document.getElementById("StartDate").value;
var dueInput = document.getElementById("DueDate").value;
var startDate = new Date(startInput);
var dueDate = new Date(dueInput);
// To calculate the time difference of two dates
var DifferenceInTime = dueDate.getTime() - startDate.getTime();
// To calculate the no. of days between two dates
var DifferenceInDays = DifferenceInTime / (1000 * 3600 * 24);
function displayDates() {
//To display the of days a student has to work on the assignment (result)
document.write("Start your assignment by " + startDate + ".<br>"
+ "Finish your assignment by " + dueDate + ".<br> "
+ "You must complete your assignment in this many days: " + DifferenceInDays + ".");
}
</script>
</body>
</html>
顺晟科技:
您调用按钮单击上的函数,但即使没有选择数据值,也会在pageload上从on input字段获取值。 您也应该将该部分放在您在单击按钮时调用的函数中。
<!DOCTYPE html>
<html>
<head>
<title>Assignment Calculator</title>
</head>
<body>
<h1>Assignment Calculator</h1>
<form>
<label for="StartDate">Date to Start:</label>
<input id="StartDate" name="StartDate" type="date"/>
<label for="DueDate">Due Date:</label>
<input id="DueDate" name="DueDate" type="date"/>
<input type="submit" value="Submit" onclick="displayDates()">
</form>
<script type = "text/javascript" >
// Get start date and due date
var startInput = document.getElementById("StartDate").value;
var dueInput = document.getElementById("DueDate").value;
var startDate = new Date(startInput);
var dueDate = new Date(dueInput);
// To calculate the time difference of two dates
var DifferenceInTime = dueDate.getTime() - startDate.getTime();
// To calculate the no. of days between two dates
var DifferenceInDays = DifferenceInTime / (1000 * 3600 * 24);
function displayDates() {
//To display the of days a student has to work on the assignment (result)
document.write("Start your assignment by " + startDate + ".<br>"
+ "Finish your assignment by " + dueDate + ".<br> "
+ "You must complete your assignment in this many days: " + DifferenceInDays + ".");
}
</script>
</body>
</html>
只需将计算日期差异的代码移到函数中。
将函数外部的所有JavaScript代码放入函数中。
<!DOCTYPE html>
<html>
<head>
<title>Assignment Calculator</title>
</head>
<body>
<h1>Assignment Calculator</h1>
<form>
<label for="StartDate">Date to Start:</label>
<input id="StartDate" name="StartDate" type="date"/>
<label for="DueDate">Due Date:</label>
<input id="DueDate" name="DueDate" type="date"/>
<input type="submit" value="Submit" onclick="displayDates()">
</form>
<script type = "text/javascript" >
// Get start date and due date
var startInput = document.getElementById("StartDate").value;
var dueInput = document.getElementById("DueDate").value;
var startDate = new Date(startInput);
var dueDate = new Date(dueInput);
// To calculate the time difference of two dates
var DifferenceInTime = dueDate.getTime() - startDate.getTime();
// To calculate the no. of days between two dates
var DifferenceInDays = DifferenceInTime / (1000 * 3600 * 24);
function displayDates() {
//To display the of days a student has to work on the assignment (result)
document.write("Start your assignment by " + startDate + ".<br>"
+ "Finish your assignment by " + dueDate + ".<br> "
+ "You must complete your assignment in this many days: " + DifferenceInDays + ".");
}
</script>
</body>
</html>
几乎所有的javsascript代码都需要在函数内部移动。
当它在代码之外时,它会立即运行,因此像and这样的变量将被设置一次,以后再也不会设置了。
您的目标是在用户单击按钮后找出并。
05
2022-12
02
2022-12
02
2022-12
29
2022-11
29
2022-11
24
2022-11