HTML5 = HTML + CSS + JS
Created by NTUgEEk
決定網頁的架構!
ex: 標題、框架、區塊…
決定網頁元素的style!
ex: 顏色、大小、對齊…
讓網頁動起來!
ex: 與使用者互動、動畫、伺服器溝通…
標籤語法,主要有兩種標籤:
<html>
<head>
<title> HTML5 is cool </title>
<meta name="author" content="NTUgEEk">
<meta charset="UTF-8">
</head>
<body>
<h1> Heading 1 </h1>
<p> Paragraph 1 : A Link <a href="google.com">Here</a> </p>
<ul> <li> List 1 </li> <li> List 2 </li> <li> List 3 </li> </ul>
</body>
</html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="link/to/style.css">
</head>
<body>
<p style="color: red;"> Paragraph to be styled </p>
</body>
</html>
p {
/* Select every <p> tag */
color: red;
border: solid 1px black;
}
.ClassName {
/* Select every tag which have class "ClassName"
Ex: <div class="ClassName">*/
float: left;
}
#IDName {
/* Select every tag which have id "IDName"
Ex: <div id="IDName"> */
text-family: monospace;
}
p a {
/* Select each <a> inside <p> */
color: red;
}
.ClassName #IDName {
/* Select every tag which have id "IDName" in class "ClassName" */
float: left;
}
p::before {
/* Insert at begin of content */
content: "I wrote:"
}
Remember to check out reference for cross browser compatibility
div {
-webkit-transition: background-color 2s;
-moz-transition: background-color 2s;
-o-transition: background-color 2s;
transition: background-color 2s;
}
Debugger: Your Browser !
Ex: Chrome - F12
Compass + Sass: A new way to write css
讓你的 Web 活起來
and much more...
比較新的 Browser 都有所謂的 Inspector 可以讓我們檢測網頁的各種資訊和狀態
<F12>
console.log("Hello JS!");
後
<Enter>
var
關鍵字來宣告if else
for
while
與 C++ 相同
function
關鍵字來宣告
function printNumber(from, to) {
if(from > to) {
console.log("Nothing to print.");
return;
}
for (var i = from; i <= to; i++)
console.log(i);
}
printNumber(4, 15);
var x = 1;
if (condition) {
var x = 2;
// somthing more...
}
console.log(x); // get output: 2
JS 中只有 funcion scope 沒有 block scope
var arr = [1, "test", 4];
console.log(arr.length); // 3
for (var i = 0; i < arr.length; i++)
console.log(arr[i]);
// 1
// test
// 4
arr.push("asdf");
console.log(arr); // [1, "test", 4, "asdf"]
console.log(arr.pop()); // asdf
push
, pop
etc)
var obj = {
name: "geek",
num: 123,
hello: function() {
console.log("hello, I'm a " + this.name);
}
};
obj.hello(); // hello, I'm a geek
obj["hello"](); // hello, I'm a geek
For more detials: Working with Objects
<html>
<head>
<script>
// your js code here
</script>
<!--or external js file-->
<script src="path/to/js/file.js"></script>
</head>
<body>
</body>
</html>
Note: script
可以放在
html
tag 中的任何地方
要用 JS 來讓 Web 動起來,就必須知道如何操作 DOM
JS 本身有提供一套 API 來操作 DOM,但也有很多的人喜歡用 jQuery
let
, const
this
: Arrow Functions