JS part6_Todolist

不重整改動頁面的情況下能取得部分頁面資料
-vertical dots->更多工具>網路開發工具->network -> 可以看到網頁有多少個網路請求
載入順序 index.html->img.src(html順序)->all.js(html順序)
100
–199
),200
–299
),300
–399
),400
–499
),500
–599
).axios.get('https://hexschool.github.io/ajaxHomework/data.json') .then(function (response) { //response是axios整理好的資訊 console.log(response.data);//data本身 console.log(response.status);//狀態馬 console.log(response.statusText); console.log(response.headers); console.log(response.config); });
function sayHello(){ //函式宣告 console.log("Hello"); Shakehand();//函式中執行函式 } function Shakehand(){ //函式宣告 console.log("Shake hand"); }
sayHello();//執行
function calculate(num1,num2){ //函式宣告 return num1+num2; } let total =calculate(1,2);//total為3
const el=document.querySelector('h1');//選取h1 const el2=document.querySelector('.header');//css選擇器 選取header class
const el=document.querySelectorAll('h1');//el會以陣列回傳el[0].el[1]..選取
el.textContent="new word"//複寫h1文字
el2.innerHTML =ˋ<h1 class="header2">h1標題</h1>ˋ//可以單引號雙引號包覆;插入class為header2的h1段落 el2.innerHTML =ˋ<h1 class="header2">${name}</h1>ˋ
const link=document.querySelector('a'); link.setAttribute("href","https:...");//更換連結屬性的連結網址("屬性","加入參數")
console.log(link.getAttribute("href"));//網址 console.log(link.innerHTML);//link<a>內標籤//輸出<span>123</span>//原html<a href=..><span>123</span>></a> console.log(link.textContent);//123
let a = 2 > 1;//也可以這樣表現 console.log(a);//輸出true
let a = 1; let b = "1"; console.log(a==b);//輸出true console.log(a===b);//輸出false console.log(a!=b);//輸出flase console.log(a!==b);//輸出true
let ary=[];//宣告方式 ary=['a',1,true];
let ary=[];//宣告方式 ary[0]='a';//['a'] ary.push("b");//新增在陣列最後->ary[1] ['a','b'] ary.unshift("c");//新增在陣列最前面['c','a','b']
ary.pop();//刪除陣列最後一項資料 ary.shift();//刪除陣列第一項資料 ary.splice(1,1);//刪除特定資料(陣列起始位置,包含自己刪除幾項資料) 輸出['C','b']
let person={ name:"Ariel", age:18 ,pet:true};//屬性:值
console.log(person);//回傳整個物件 console.log(person.age);//取出18
console.log(person['age']);//另一種方式 let a='age'; console.log(person[a]);//另一種方式;if JSON格式 若屬性名稱為01就無法使用peron.01
person.sibiling=['Eric','Tom'];
delete person.pet; console.log(person.pet);//undefined
let person=[ { name:"Ariel", age:18, pet:true }, { name:"Eric", age:15, pet:false } ]
console(person[0].name);//Ariel
let Ariel={ sex:female, dog:{ name:"Small", age:2, }, cat:{ [ { name:"Meowmeow", age:5, color:"black" }, { name:"leeya", age:3, color:"orange" } ] } } console.log(Ariel.dog.name);//Small console.log(Ariel.cat[1].age);//3
let a = "let's go";
let b = 'shall we?';
console(a+' '+b) //let's go shall we ( ' ' 內為空白 )
let name='Ariel';
let age=18;
let total=name+age
console.log(typeof total);//輸出string
//有些情況下會自動轉型使之能以字串形式相加
let total=name*age;//字串*數字
console.log(typeof total);//輸出NaN
a.length("30");//字串轉型為數值
a.trim();//字串轉型為數值
let content="你好我是"+name+"我現在"+age+"歲";
let content=ˋ你好我是${name},我現在${age}歲ˋ; //利用ˋ反斜單引號包整個字串,${}放入變數
let a;
console.log(a)//輸出undefined
let c=null;
console.log(c);//輸出null
let num=parseInt("30");//字串轉型為數值
let a=25;//number let word=a.toString();//"25"數值轉型為字串