我正在尝试在线阅读有关如何制作Todo列表的教程
我完成了以下代码,如下所示
<!doctype html>
<html>
<head>
<title>To do list with html and javascript</title>
<style>
ul { list-style: none; padding: 0; margin: 0; width: 400px;}
li { border: 1px solid #ccc; background: #eee; padding: 5px 10px; color: #000; }
li span { padding-left: 10px; cursor: default;}
.checked { text-decoration: line-through; font-weight: bold; color: #c00;}
</style>
</head>
<body>
<h1>To Do List</h1>
<p><iput type="text" id="inItemText"/>
<ul id= "todolist">
</ul>
<script type= "text/javascript" src="todo.js"</script>
</body>
</html>
和
// Each item should look like <li><input type = "checkbox"/> do tutorial</li>
function updateItemStatus (){
var cbId = this.id.replace("cb_","");
var itemText = document.getElementbyId("item_" + cb.Id);
if (this.checked) {
itemText.className = "checked";
} else {
itemText.style.fontWeight = "";
}
}
function removeItem(){
var spanId = this.id.replace("item","");
document.getElementById("li_" + spanId).style.display = "none";
}
function addNewItem(list, itemText){
var date = new Date ();
var id = "" + date.getHours() + date.getMinutes() + date.getSeconds() + date.getMilliseconds(); ;
var listItem = document.createElement("li");
list.Item.id = "li_" + id;
var checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.id = "cb_" + id;
checkBox.oneclick = updateItemStatus;
var span = document.createelement("span");
span.id = "item_" + id;
span.innertext = itemText;
span.ondblclick = removeItem;
listItem.appendChild(checkbox);
listItem.appendChild(span)
list.appendChild(listItem);
}
var inItemText = document.getElementbyId("inItemText");
inItemText.focus();
inItemText.onkeyup = function (event) {
// 13 means Enter
if (event.which == 13) {
var itemText = event.which;
if (itemText == "" || itemText == " ") {
return false;
}
addNewItem(document.getElementById("todolist") itemText);
inItemText.focus();
inItemText.select();
};
我将这两个文件保存在桌面上的保存文件夹中。 javascript仍然没有出现。我输错了吗?我只是想尝试如何将javascript链接到我的html抱歉,这是我第一次这样做。
答案 0 :(得分:0)
你忘记了>
<script type= "text/javascript" src="todo.js"></script>
答案 1 :(得分:0)
<script type= "text/javascript" src="todo.js"></script>
这就是全部..因为您忘记了>
HTML认为您的代码永远不会结束,直到它看到下一个>
...