出于某种原因,它没有接受 onsubmit。我不知道为什么,我没有收到任何错误。我也检查了拼写错误和标点符号,所以我不知道出了什么问题。任何想法都会有很大帮助!非常感谢!
这是我的 HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>To-Do List</title>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="stylesheet" href="css/form.css">
</head>
<body>
<!-- tasks.html -->
<form action="#" method="post" id="theForm">
<fieldset><legend>Enter an Item To Be Done</legend>
<div><label for="task">Task</label><input type="text" name="task" id="task" required></div>
<div><label for="priority">Priority</label> <select name="priority" id="priority">
<option value="high">High</option>
<option value="normal" selected>Normal</option>
<option value="low">Low</option>
</select></div>
<input type="submit" value="Add It!" id="submit">
<div id="output"></div>
</fieldset>
</form>
<script src="js/tasks.js"></script>
</body>
</html>
这是javascript
function Task(name, priority) {
'use strict';
this.name = name;
this.priority = priority;
this.completed = false;
this.toString = function() {
return this.name + ' (' + this.priority + ')';
};
} // End of Task function.
Window.onload = function(){
'use strict';
var task = document.getElementById('task');
var priority = document.getElementById('priority');
var output = document.getElementById('output');
var tasks = [];
document.getElementById('theForm').onsubmit = function() {
var t = new Task(task.value, priority.value);
tasks.push(t);
output.innerHTML = 'There are now <b>' + tasks.length + '</b> item(s) in the to-do list. Just added:<br>' + t.toString();
return false;
}; // End of onsubmit anonymous function.
}; // End of onload anonymous function.