<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script>
document.write("可以寫 JavaScript 的地方1:head 標籤內");
</script>
</head>
<body>
<header></header>
<section>
<script>
document.write("可以寫 JavaScript 的地方2:body 標籤內");
</script>
<script src="hello.js">
document.write("Test!")
</script>
<script>
var ret=alert("警告!");
document.write("alert!結束...")
</script>
<script>
var ret=confirm("確認?")
document.write("<p>confirm結果傳回:"+ret+"</p>");
</script>
<script>
var ret=prompt("請輸入帳號:");
document.write(""+ret);
</script>
</section>
<footer></footer>
</body>
</html>
-----------------------------------------------------------------2020-10-16
https://www.youtube.com/watch?v=35sPvHtT8iY&list=PLGBY4JjI_1Pgeq1vqOAZVlM7FzCrKkK-c&index=11
---------------------------------------------------------------------
var todos=["do1","do2","do3"] //Array
------------------------------------------------------------------函式
var todos=["k1","k2","k3"]
function displayTodos(){
console.log(todos)
}
displayTodos()
["k1", "k2", "k3"]
function addTodos(todo){
todos.push(todo)
displayTodos()
}
addTodos("Addtest")
["k1", "k2", "k3", "Addtest"]
function changeTodo(position,newTodo){
todos[position]=newTodo
displayTodos()
}
changeTodo(0,"updatedTodo")
["updatedTodo", "k2", "k3", "Addtest"]
function deleteTodo(position){
todos.splice(position,1)
displayTodos()
}
deleteTodo(2)
["updatedTodo", "k2", "Addtest"]
----------------------------------------------------------------物件
var person={
name:"John", //屬性
sayName:function(){ //方法
console.log("Hi my name is",this.name)
}
}
person.name
"John"
person.sayName()
Hi my name is John
----------------------------------------------------------------
var todos={
todos:["k1","k2","k3"],
displayTodo:function(){
console.log(this.todos);
},
addTodo:function(todo){
this.todos.push(todo);
this.displayTodo()
},
changTodo:function(position,newvalue){
this.todos[position]=newvalue;
this.displayTodo()
},
deleteTodo:function(position){
this.todos.splice(position,1);
this.displayTodo()
}
todos.displayTodo()
["k1", "k2", "k3"]
todos.addTodo("newk")
["k1", "k2", "k3", "newk"]
todos.changTodo(0,"updated")
["updated", "k2", "k3"]
todos.deleteTodo(0)
["k2", "k3"]