หนว ยท่ี 1 ภาษา HTML ครูวิรยา สีขาว
การใสเ พลงประกอบในเวบ็ เพจ ภาษา HTML5
<BODY > <BGSOUND SRC=\"beliveme.mp3\" LOOP=\"Infinite\"> </BODY>
BGSOUND เปนแท็กคาํ สง่ั เพือ่ บอกใหเ บราสเซอรรวู า จะตอง ดาวนโ หลดเพลงมาบรรเลงประกอบหนา เว็บเพจ SRC=\"ชอ่ื เพลง\" เปนการกําหนดแหลง ท่ีเกบ็ และชอื่ เพลงที่ ตอ งการใหเบราสเ ซอรด าวนโหลดมาบรรเลง LOOP=\"infinite\" เปน การกําหนดใหเบราสเซอรเลน เพลงไป เรื่อยๆ ถาไมตอ งการใหลบขอ ความนอี้ อกไป
การทาํ ล้ิงคเพ่อื ใชสงอีเมล (Mailto:)
<BODY> แบบท่ี 1 ลง้ิ คข อ ความธรรมดา<p> <A HREF=\"Mailto:[email protected]\">สง อเี มลถ งึ อ.วิรยา สขี าว</A> แบบที่ 2 ใชร ปู ภาพเปนลงิ้ ค เพื่อเพิม่ ความ นาสนใจ<p> <A HREF=\" [email protected]\"><IMG SRC=\"mail2.gif\" BORDER=\"0\"></A> </BODY>
อธิบายคาํ สงั่ Mailto:ทอี่ ยอู ีเมล@ ปลายทาง เปนการสรางลงิ้ ค เพือ่ สงอีเมล โดยใชโปรแกรมอีเมลในเคร่อื งของ ผูสงเชน Outlook Express
การแทรกไฟล Multimedia การใสไ ฟลม ลั ตมิ เี ดยี เชน ไฟลเสยี ง เพลง, Video, Flash เราสามารถใสไ ฟลเ พลง, ไฟล video หรือไฟล flash ลงไปในหนา เวบ็ เพจได ดว ยคาํ ส่งั <embed> <embed> เปน คาํ สั่งแสดงการทาํ งานของโปรแกรม plug-in โดย นําไปผนวกกับเอกสาร HTML และอาจใส tag <noembed> ควบคู ไปดว ย เผ่อื เว็บเบราเซอรรนุ เกา ท่ยี ังไม support tag <embed> นี้. โครงสรา งของคาํ ส่ังการแทรกไฟล Multimedia <embed src=\"url ไฟล\" width=\"number\" height=\"number\" > <noembed><img src=\"url ไฟลรูปภาพที่ใหแสดงเมือ่ ใช embed ไมไ ด\" ></noembed> </embed>
คาํ ส่งั เสรมิ สําหรบั <embed> - src=\"url\" url ของไฟลท่ีจะใหเ ลน ไดแ ก ไฟลเสียง (เชน .mid, .wav, .mp3) ไฟล vedio (เชน .avi, wmv, mov, mpeg) และไฟล Flash movie ( .swf) - width=\"no\" กําหนดขนาดความกวางของตวั player - height=\"no\" กําหนดขนาดความสงู ของตวั player - align=\"top | middle | bottom | left | right\" จัดวางตาํ แหนง ใหก ับวตั ถุ ที่อยูขางๆ ตวั player - name=\"ชือ่ \" ช่ืออา งอิงของวัตถุ - autostart=\"true | false\" เมื่อโหลดเว็บเพจแลว ใหเลนอัตโนมัติหรอื ไม - loop=\"true | false | number\" กาํ หนดเปน true เม่ือตอ งการใหเ ลนซาํ้ ไปเร่อื ยๆ หรือกําหนดเปนตัวเลข จํานวนรอบทต่ี อ งการใหเ ลนซํ้า - playcount=\"no\" จาํ นวนรอบท่ใี หเลน (ใชไดเ ฉพาะ IE) - hidden=\"true | false\" ใหซอน หรือแสดงตวั player - volume=\"0 ถึง 100\" กําหนด volume ของเสียง (ใชไดเ ฉพาะ Netscape)
การแทรกไฟลเ สยี ง ตวั อยา งการใชค าํ ส่งั เลน ไฟลเสยี ง <embed src=“music01.mp3\" width=\"100%\" height=\"60\"> <noembed><img src=\"nosupport.gif\" ></noembed> </embed>
คาํ สั่งเลนเสยี งและวดี โี อดว ยภาษา HTML5
การใสเ สยี งในภาษา HTML5 <audio controls=\"controls\"> <source src=“testsound.ogg\" type=\"audio/ogg\"> <source src=“testsound.mp3\" type=\"audio/mpeg\"> Browser ของคณุ ไมสนับสนนุ การเลน ไฟลเ สยี งดว ย HTML5 </audio>
การใสไ ฟลวีดโี อดว ย HTML5 <video width=“1000\" height=“800\" controls=\"controls\"> <source src=“testmovie.mp4\" type=\"video/mp4\"> <source src=“testmovie.ogg\" type=\"video/ogg\"> Browser ของคณุ ไมส นับสนนุ การเลนไฟลว ดี โี อดว ย HTML5 </video>
การเลน วดี โี อแบบอัตโนมตั ิ <!DOCTYPE html><html><body> <video width=\"320\" height=\"240\" autoplay> <source src=\"movie.mp4\" type=\"video/mp4\"> <source src=\"movie.ogg\" type=\"video/ogg\"> Your browser does not support the video tag. </video> <p><b>Note:</b> The autoplay attribute does not work on some mobile devices.</p> </body></html>
การสรางปมุ โตต อบกบั การเลนวีดีโอ <!DOCTYPE html> <html> <body> <div style=\"text-align:center\"> <button onclick=\"playPause()\">Play/Pause</button> <button onclick=\"makeBig()\">Big</button> <button onclick=\"makeSmall()\">Small</button> <button onclick=\"makeNormal()\">Normal</button> <br><br> <video id=\"video1\" width=\"420\"> <source src=\"mov_bbb.mp4\" type=\"video/mp4\"> <source src=\"mov_bbb.ogg\" type=\"video/ogg\"> Your browser does not support HTML5 video. </video></div> <script>
การสรางปมุ โตต อบกับการเลน วีดีโอ (ตอ ) var myVideo = function makeSmall() { document.getElementById( myVideo.width = \"video1\"); 320; function playPause() { } if (myVideo.paused) function makeNormal() { myVideo.play(); else myVideo.pause(); myVideo.width = 420; } } function makeBig() { </script></body> </html> myVideo.width = 560; }
HTML Plug-ins เปนคาํ ส่งั ท่ีใชสาํ หรบั แทรกไฟลต างๆ swf , pdf , Flash Player ตา งๆ ในหนาเว็บเพจ มดี ว ยกนั สอง คําส่ังคอื แทก็ <object> และ<embed>
การใชแทก็ <object> <!DOCTYPE html> <html><body> <object width=\"400\" height=\"50\" data=\"bookmark.swf\"></object> <object width=“800\" height=\"500\" data=“.pdf\"></object> </body></html>
การใชแท็ก <object> การแทรกหนา เว็บเพจในหนาเวบ็ เพจ <object width=\"100%\" height=\"500px\" data=“index.html\"></object> การใสร ูปภาพ <object data=“images/02.jpg\"></object>
การใชแท็ก <embed > <!DOCTYPE html> <html><body> <embed width=\"400\" height=\"50\" src=\"bookmark.swf\"> </body></html>
การใชแทก็ <embed > <embed width=\"100%\" height=\"500px\" src=\"index.html\"> <embed src=\"images/images02.jpg\"> <embed width=\"100%\" height=\"500px\" src=\"Document1.pdf\">
Semantics เทคโนโลยีกลมุ Semantics คอื ตวั syntax ของภาษา HTML5 ท่ีแนน อนวาเปล่ยี นไปจาก HTML4 ซึ่งมแี ท็ก ใหมๆ และคณุ สมบัติ (atrribute) ใหมๆ เพม่ิ ข้นึ
HTML Layout Elements
Tag ใน HTML5 section - บง บอกเซคชนั ของเนอื้ หา article - กําหนดขอบเขตของตัวเนอื้ บทความ aside - กําหนดขอบเขตของเนื้อหาเสรมิ (ลอ มกรอบ) header - กาํ หนดขอบเขตของสวนเรมิ่ ตน หรอื สวนหวั ของเวบ็ ไซต (อยา สบั สนกับ <head>) footer - กาํ หนดขอบเขตของสว นทา ยของเวบ็ ไซต พวกขอ ความกาํ หนด สทิ ธิต์ า งๆ nav - บอกวามนั เปนสว นนาํ ทางของเว็บไซต figure - บอกวาเปน ภาพหรือวิดโี อประกอบเนือ้ หา (ขางในสามารถซอน แท็ก img หรอื video พรอ มคําอธิบายไดอกี ช้นั )
article - กําหนดขอบเขตของตัวเน้ือบทความ <article> <h1>ภาษา HTML5</h1> <p>HTML5 ก็คือภาษาที่ถูกพัฒนาขน้ึ เพือ่ ใชเปน ภาษามารก อพั <BR>สําหรบั การเขียน Website รนุ ลา สุดท่ีไดถ กู พัฒนาขน้ึ มา<BR>โดย WHATWG </p> </article>
Tag <section> ความหมายและการใชง าน คือ การแบง กลมุ เนอื้ หาออกเปนสว นๆ เชน การแบง บทความออกเปน chapter หรอื แบง เนอ้ื หาทั้งหมดออกเปนประเดน็ ยอ ยๆ อยางการแบง ขา วออกเปน กลมุ ของขา วในพระราชสาํ นกั กลมุ ของขา วกฬี า กลมุ ของขา ว บันเทงิ เปน ตน โดยท่ัวไปเรามกั จะใช Section ภายใน Article และ เนอ้ื หาภายใน section จะตอ งเก่ยี วขอ งกันท้งั หมด ทีส่ าํ คญั คอื section ไมไ ดใ ชสาํ หรับแบงเว็บเพจออกเปน สว นๆ ไมไ ดใชสาํ หรบั ทํา Layout ถา อยากทํา Layout ใหใ ช div แทน
<section> <h2>ภาษา HTML5</h2> <p>HTML5 ก็คือภาษาที่ถกู พัฒนาข้นึ เพอ่ื ใชเ ปน ภาษามารก อัพ <BR>สาํ หรบั การเขียน Website รนุ ลา สดุ ที่ไดถ ูกพฒั นาข้ึนมาโดย<BR> WHATWG </p> </section>
Tag <aside> ความหมายและการใชงาน <aside> สวนของเน้ือหาท่ีเกยี่ วของกบั เนอ้ื หาหลกั ท่ีอยโู ดยรอบ โดยมี จดุ ประสงคเ พือ่ ใหแยกออกจากเนอื้ หาหลัก และใชเ ปนกรอบคําอธิบายเพม่ิ เติมทเี่ กีย่ วของกับเน้ือหาหลกั และนอกจากนี้ <aside> ยงั สามารถใชเปน สว นของ แถบดานขา ง (Sidebar) ไดอ ีก ดวย
<aside> <h2>ภาษา HTML5<BR> HTML5 กค็ ือภาษาทีถ่ กู พัฒนาขน้ึ เพอื่ ใชเปน ภาษา มารกอัพ <BR>สาํ หรับการเขยี น Website รุนลาสดุ ท่ไี ดถ กู พฒั นาขึ้นมาโดย<BR> WHATWG </h2> </aside>
Tag <nav> ความหมายและการใชง าน tag nav คือ การนําทางหรอื ล้งิ คนาํ ทาง nav ไมจาํ เปนตอ ง ใสอนั ตอ อนั สามารถใสค รอบคลุมทเี ดยี วหลายๆอนั ไดเลย
<nav> <a href=”/html/”>HTML</a> | <a href=”/css/”>CSS</a> | <a href=”/js/”>JavaScript</a> | <a href=”/jquery/”>jQuery</a> </nav>
Tag <header> ความหมายและการใชง าน เปน element ท่ใี ชค รอบเนอ้ื หาท่เี ปนตน ขว้ั ของเอกสาร โดยวิธกี ารใชจะ ข้นึ ดว ย <header> …… </header>
<html><body> <header> <h1>Heading A</h1> <p>เนือ้ หาสวนน้ีเปน ของ Heading A</p> <h2>Heading B</h2> <p>เน้ือหาสวนนเ้ี ปน ของ Heading B</p> <h2>Heading C</h2> <p>เนอ้ื หาสว นนเ้ี ปน ของ Heading C</p> </header></body></html>
Tag <footer> ความหมายและการใชง าน แทก็ footer เปน แทก็ ที่ใชสาํ หรบั ใสอะไรกไ็ ดทอ่ี ยูด านลา งๆ อยา งเชน creadit ผูแตงเว็บไซต หรอื หนา site map รวบรวมลงิ้ กของเวบ็ ไซต เราเอง
<footer> <p>Posted by: Hege Refsnes</p> <p>Contact information: [email protected] </p> </footer>
HTML Iframes <!DOCTYPE html> <html><body> <h2>HTML Iframes</h2> <p>You can use the height and width attributes to specify the size of the iframe:</p> <iframe src=\"demo_iframe.htm\" height=\"200\" width=\"300\"></iframe> </body></html>
HTML Iframes <!DOCTYPE html><html><body> <h2>HTML Iframes</h2> <p>You can also use the CSS height and width properties to specify the size of the iframe:</p> <iframe src=\"demo_iframe.htm\" style=\"height:200px;width:300px\"></iframe> </body></html>
HTML Iframes <!DOCTYPE html> <html><body> <h2>Custom Iframe Border</h2> <p>With CSS, you can also change the size, style and color of the iframe's border:</p> <iframe src=\"demo_iframe.htm\" style=\"border:2px solid red;\"></iframe> </body> </html>
Iframe - Target for a Link <!DOCTYPE html><html><body> <h2>Iframe - Target for a Link</h2> <iframe height=\"300px\" width=\"100%\" src=\"demo_iframe.htm\" name=\"iframe_a\"></iframe> <p><a href=\"https://www.w3schools.com\" target=\"iframe_a\">W3Schools.com</a></p> <p>When the target of a link matches the name of an iframe, the link will open in the iframe.</p> </body></html>
My First JavaScript <!DOCTYPE html> <html><body> <h1>My First JavaScript</h1> <button type=\"button\" onclick=\"document.getElementById('demo').innerHT ML = Date()\"> Click me to display Date and Time.</button> <p id=\"demo\"></p> </body></html>
<!DOCTYPE html><html><body> <h1>My First JavaScript</h1> <p id=\"demo\">JavaScript can change the style of an HTML element.</p> <script> function myFunction() { document.getElementById(\"demo\").style.fontSize = \"25px\"; document.getElementById(\"demo\").style.color = \"red\"; document.getElementById(\"demo\").style.backgroundColor = \"yellow\"; } </script> <button type=\"button\" onclick=\"myFunction()\">Click Me!</button></body></html>
JavaScript can change HTML attributes <!DOCTYPE html> document.getElementById('myImage' <html><body> ).src = pic; <script> function light(sw) { } var pic; if (sw == 0) { </script> pic = \"pic_bulboff.gif\" } else { <img id=\"myImage\" pic = \"pic_bulbon.gif\" src=\"pic_bulboff.gif\" width=\"100\" } height=\"180\"> <p> <button type=\"button\" onclick=\"light(1)\">Light On</button> <button type=\"button\" onclick=\"light(0)\">Light Off</button></p></body></html>
Search
Read the Text Version
- 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
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109