Submit Search
Javascript Tutorial
9 likes
2,580 views
Kang-min Liu
The javascript tutorial talk for openfoundry
Technology
Read more
1 of 93
Download now
Downloaded 310 times
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
More Related Content
More from Kang-min Liu
(19)
PDF
o̍h Tai-gi
Kang-min Liu
PDF
The architecture of search engines in Booking.com
Kang-min Liu
PDF
Elasticsearch 實戰介紹
Kang-min Liu
KEY
Perlbrew
Kang-min Liu
PDF
Same but Different
Kang-min Liu
PDF
perlbrew yapcasia 2010
Kang-min Liu
PDF
Git
Kang-min Liu
KEY
Good Evils In Perl (Yapc Asia)
Kang-min Liu
KEY
Learning From Ruby (Yapc Asia)
Kang-min Liu
KEY
YAPC::Tiny Introduction
Kang-min Liu
PDF
Integration Test With Cucumber And Webrat
Kang-min Liu
PDF
Good Evils In Perl
Kang-min Liu
PDF
Javascript Basic
Kang-min Liu
PDF
Handlino - RandomLife
Kang-min Liu
PDF
Jformino
Kang-min Liu
PDF
Test Continuous
Kang-min Liu
PDF
網頁程式還可以怎麼設計
Kang-min Liu
PDF
OSDC.tw 2008 Lightening Talk
Kang-min Liu
PDF
Happy Designer 20080329
Kang-min Liu
o̍h Tai-gi
Kang-min Liu
The architecture of search engines in Booking.com
Kang-min Liu
Elasticsearch 實戰介紹
Kang-min Liu
Perlbrew
Kang-min Liu
Same but Different
Kang-min Liu
perlbrew yapcasia 2010
Kang-min Liu
Git
Kang-min Liu
Good Evils In Perl (Yapc Asia)
Kang-min Liu
Learning From Ruby (Yapc Asia)
Kang-min Liu
YAPC::Tiny Introduction
Kang-min Liu
Integration Test With Cucumber And Webrat
Kang-min Liu
Good Evils In Perl
Kang-min Liu
Javascript Basic
Kang-min Liu
Handlino - RandomLife
Kang-min Liu
Jformino
Kang-min Liu
Test Continuous
Kang-min Liu
網頁程式還可以怎麼設計
Kang-min Liu
OSDC.tw 2008 Lightening Talk
Kang-min Liu
Happy Designer 20080329
Kang-min Liu
Javascript Tutorial
1.
Handlino http://handlino.com/ Javascript Tutorial Kang-min
Liu
2.
Handlino http://handlino.com/ Tools • Firefox
3 • Firebug • “shell” and “test styles” bookmarklets • https://www.squarefree.com/ bookmarklets/webdevel.html ( http://is.gd/45YH )
3.
Handlino http://handlino.com/ “Bread board” <html><body> <script
type="text/javascript"> // Code goes here... </script> </body></html> Save it as “test.html” http://gist.github.com/31863
4.
Handlino http://handlino.com/ Code
5.
Handlino http://handlino.com/ Hello World alert("Hello
World");
6.
Handlino http://handlino.com/ Hello, you var
nickname = "gugod"; alert("Hello, " + nickname);
7.
Handlino http://handlino.com/ Hello, you var
nickname = "gugod"; alert("Hello, " + nickname);注意
8.
Handlino http://handlino.com/ variables 變數 var
nickname = "gugod";
9.
Handlino http://handlino.com/ variables 變數 variable name var
nickname = "gugod";
10.
Handlino http://handlino.com/ variables 變數 variable name variable value var
nickname = "gugod";
11.
Handlino http://handlino.com/ variables 變數 variable name variable value var
nickname = "gugod"; declare
12.
Handlino http://handlino.com/ variables 變數 var
nickname = “gugod”;
13.
Handlino http://handlino.com/ variables 變數 var
nickname = 610;
14.
Handlino http://handlino.com/ variables 變數 var
nickname = x;
15.
Handlino http://handlino.com/ SimpleVariableValues var nickname
= "gugod"; var answer = 42; alert(nickname); alert(answer);
16.
Handlino http://handlino.com/ SimpleVariableValues nickname =
"gugod"; answer = 42; alert(nickname); alert(answer);
17.
Handlino http://handlino.com/ SimpleVariableValues nickname =
"gugod"; answer = 42; alert(nickname); alert(answer); 貌似全域變數
18.
Handlino http://handlino.com/ 變數領域 var nickname
= "gugod"; function test1() { nickname = 610; } function test2() { nickname = 5566; }
19.
Handlino http://handlino.com/ 變數領域 var nickname
= "gugod"; function test1() { var nickname = 610; } function test1() { var nickname = 5566; }
20.
Handlino http://handlino.com/ 全域變數 • 不是宣告在
function 裡面的 • 沒有事先宣告的 • 名稱為 “window.XXX” 型式的
21.
Handlino http://handlino.com/ 全域變數 var nickname
= "gugod"; function test1() { nickname = 610; } function test2() { nickname = 5566; }
22.
Handlino http://handlino.com/ 全域變數 var nickname
= "gugod"; function test1() { nickname = 610; } function test2() { nickname = 5566; } 全域變數
23.
Handlino http://handlino.com/ 全域變數 function test1()
{ nickname = 610; } function test2() { var n = window.nickname; } 610
24.
Handlino http://handlino.com/ if-else if (<expression>)
{ ... } else { ... }
25.
Handlino http://handlino.com/ if-else if (<expression>)
{ ... }
26.
Handlino http://handlino.com/ if-else if (<expression>)
{ ... } else if (<expression>){ ... } else if (<expression>){ ... } else { ... }
27.
Handlino http://handlino.com/ Expressions a ==
b a != b a >= b a <= b a > b a < b a && b a || b a
28.
Handlino http://handlino.com/ if-else if (10
< a && a < 42) { ... }
29.
Handlino http://handlino.com/ if-else // 10
< a < 42 if (10 < a && a < 42) { ... }
30.
Handlino http://handlino.com/ if-else // 10
< a < 42 if (10 < a && a < 42) { ... } 程式碼 解
31.
Handlino http://handlino.com/ if-else // 10
< a < 42 if (10 < a && a < 42) { ... } // 42 ~ 50 else if (a >= 42 && a <= 50) { ... } // ? ~ 10 else { ... }
32.
Handlino http://handlino.com/ Function 函式
33.
Handlino http://handlino.com/ Function function hello()
{ alert("hello"); }
34.
Handlino http://handlino.com/ Function var hello
= function() { alert("hello"); }
35.
Handlino http://handlino.com/ Function call hello();
36.
Handlino http://handlino.com/ Function call hello();
37.
Handlino http://handlino.com/ Function w/
Argument function hello(x) { alert("hello " + x); }
38.
Handlino http://handlino.com/ Function call hello("gugod");
39.
Handlino http://handlino.com/ Function call hello("gugod");
40.
Handlino http://handlino.com/ Function call hello(a);
41.
Handlino http://handlino.com/ var hello
= function(nickname, like) { var message = "hello " + nickname; if (like > 6) { message = "Great to see you, " + nickname; } if (like < 2){ message = "Oh, it’s you, " + nickname; } alert(message); }
42.
Handlino http://handlino.com/ Function 傳回值 function
add3(a) { return a + 3; }
43.
Handlino http://handlino.com/ Function 傳回值 function
add3(a) { return a + 3; }
44.
Handlino http://handlino.com/ Input
45.
Handlino http://handlino.com/ • Browser
User Input • prompt() • DOM (HTML) • Ajax • iframe, XMLHttpRequest, JSONRequest, JSONP, ...
46.
Handlino http://handlino.com/ var a
= prompt("Give me money:"); alert(a); prompt
47.
Handlino http://handlino.com/ prompt • Good •
Easy • Built-in • Bad • No way to customize style • One variable at a time
48.
Handlino http://handlino.com/ DOM <html><body> <span id="nickname">gugod</span> <script
type="text/javascript"> // Code... </script> </body></html>
49.
Handlino http://handlino.com/ <html><body> <span id="nickname">gugod</span> <script
type="text/javascript"> var nickname = document.getElementById("nickname") .childNodes[0] .nodeValue; alert(nickname); </script> </body></html>
50.
Handlino http://handlino.com/ <html><body> <span id="nickname">gugod</span> <script
type="text/javascript"> var nickname = document.getElementById("nickname") .childNodes[0] .nodeValue; alert(nickname); </script> </body></html>
51.
Handlino http://handlino.com/ <html><body> <span id="nickname">gugod</span> <script
type="text/javascript"> var nickname = document.getElementById("nickname") .childNodes[0] .nodeValue; alert(nickname); </script> </body></html>
52.
Handlino http://handlino.com/ <head> <script type="text/javascript" src="jquery.min.js"></script> </head> Add jQuery
53.
Handlino http://handlino.com/ Hello (jQuery) <html> <head> <script
type="text/javascript" src="jquery.js"></script> </head> <body> <span id="nickname">gugod</span> <script type="text/javascript"> var nickname = $("#nickname").text(); alert(nickname); </script> </body></html>
54.
Handlino http://handlino.com/ Hello (jQuery) <html> <head> <script
type="text/javascript" src="jquery.js"></script> </head> <body> <span id="nickname">gugod</span> <script type="text/javascript"> var nickname = $("#nickname").text(); alert(nickname); </script> </body></html>
55.
Handlino http://handlino.com/ Hello (jQuery) <html> <head> <script
type="text/javascript" src="jquery.js"></script> </head> <body> <span id="nickname">gugod</span> <script type="text/javascript"> var nickname = $("#nickname").text(); alert(nickname); </script> </body></html>
56.
Handlino http://handlino.com/ Output
57.
Handlino http://handlino.com/ • Browser
Built-in • alert() • DOM • Ajax • HTTP POST
58.
Handlino http://handlino.com/ <span id="output"></span> <script
type="text/javascript"> var message = "Hello, world"; $("#output").text(message); </script> DOM
59.
Handlino http://handlino.com/ Input +
Output <span id="output"></span> <script type="text/javascript"> var message = "Hello, " + prompt("Your name is: "); $("#output").text(message); </script>
60.
Handlino http://handlino.com/ Other Topics
61.
Handlino http://handlino.com/ ☻Intermission☺
62.
Handlino http://handlino.com/ jQuery jquery.com
63.
Handlino http://handlino.com/ CSS
64.
Handlino http://handlino.com/ p { line-height:
1.5em; }
65.
Handlino http://handlino.com/ query { property:
value; }
66.
Handlino http://handlino.com/ query1, query2
{ property1: value1; property2: value2; property3: value3; }
67.
Handlino http://handlino.com/ h1, h2
{ font-family: Helvectica; color: #555; border-bottom: 1px solid #aaa; }
68.
Handlino http://handlino.com/ h1, h2
{ font-family: Helvectica; color: #555; border-bottom: 1px solid #aaa; } h1 { font-size: 2em; } h2 { font-size: 1.5em; }
69.
Handlino http://handlino.com/ 選元素
70.
Handlino http://handlino.com/ 選元素 • tagname •
#id • .class • tag[attr=value] • h1, h2, div • <div id=”nav”> • <h1 class=”title”> • <input name=”nick”>
71.
Handlino http://handlino.com/ jQuery 選元素 •
$(“h1”) • $(“#id”) • $(“.class”) • $(“input[name=nick]”)
72.
Handlino http://handlino.com/ jQuery
73.
Handlino http://handlino.com/ jQuery 選元素 •
jQuery(“h1”) • jQuery(“#id”) • jQuery(“.class”) • jQuery(“input[name=nick]”)
74.
Handlino http://handlino.com/ jQuery 選元素 •
$(“h1”) • $(“#id”) • $(“.class”) • $(“input[name=nick]”)
75.
Handlino http://handlino.com/ $
76.
Handlino http://handlino.com/ function $(query)
{ var elements = <magic>; return elements; }
77.
Handlino http://handlino.com/ 試玩 jQuery •
Grab jQuerify: http://is.gd/aab6 • Visit google.com • Click jQuerify • Click js shell
78.
Handlino http://handlino.com/ Let’s play
some jQuery $("input").size(); $("input[name=q]").val("Taipei"); $("input[name=btnI]").click();
79.
Handlino http://handlino.com/ Let’s play
some jQuery $("input").hide(); $("input").show("slow"); $("input").css({ "background": "red" });
80.
Handlino http://handlino.com/ jQuery collections •
$() 會傳回 jQuery collection,「一群元 素」 • 可以對其呼叫各種方法,同時操作 群 元素
81.
Handlino http://handlino.com/ 操作一群元素 $("div.section").addClass("highlight"); $("img.photo").attr("src", "img/hi.png"); $("a.foo").html("<em>Click
me</em>"); $("p:odd").css("background","#ccc");
82.
Handlino http://handlino.com/ 取得各種值 var height
= $("div#first").height(); var img_src = $("img.photo").attr("src"); var lastP = $("p:last").html();
83.
Handlino http://handlino.com/ Other topics •
DOM Traversal • Browser Events • Ajax • Plugins • Effects • UI
84.
Handlino http://handlino.com/ Effect
85.
Handlino http://handlino.com/ jQuery hide <div
id="hello">Hello</div> <script type="text/javascript"> $("#hello").hide('slow'); </script>
86.
Handlino http://handlino.com/ Show on
click <script type="text/javascript"> $("#hi").click(function() { $("#hello").slideDown(); }); </script> #hello { display: none } <a href="#" id="hi">Hi</a> <div id="hello">Hello</div> HTML CSS Javascript http://gist.github.com/31889
87.
Handlino http://handlino.com/ Show on
click <script type="text/javascript"> $("#hi").click(function() { $("#hello").slideToggle(); }); </script> #hello { display: none } <a href="#" id="hi">Hi</a> <div id="hello">Hello</div> HTML CSS Javascript http://gist.github.com/31892
88.
Handlino http://handlino.com/ Show on
click <script type="text/javascript"> $("#hi").click(function() { $("#hello").slideToggle(); }); </script> #hello { display: none } <a href="#" id="hi">Hi</a> <div id="hello">Hello</div> HTML CSS Javascript http://gist.github.com/31892
89.
Handlino http://handlino.com/ More Info •
http://jquery.com/ • http://visualjquery.com/
90.
Handlino http://handlino.com/ 作業 • 試寫一
BMI 計算機。輸入身高 (cm) 與體 重 (kg),並顯示出 BMI • BMI = 體重 / 身高2 公尺
91.
Handlino http://handlino.com/ 予想界面
92.
Handlino http://handlino.com/ 解答 http://gist.github.com/31899
93.
Handlino http://handlino.com/ 謝謝 ご清聴ありがとうございました
[email protected]
[email protected]
Download