JavaScript_DOMѧϰƪ_ͼƬÇл»Ð¡°¸Àý
2018-07-22 06:06:51À´Ô´£º²©¿ÍÔ° ÔĶÁ ()
½ñÌ쿪ʼѧϰDOM²Ù×÷,ÏÂÃæдһ¸öС°¸ÀýÀ´¹®¹ÌÏÂ֪ʶµã.
DOM: document object model (Îĵµ¶ÔÏóÄ£ÐÍ)
¸ù¾Ýid»ñÈ¡Ò³ÃæÔªËØ :¡¡Èç:¡¡var xx = document.getElementById("id");
¸ù¾Ý±êÇ©»ñÈ¡ÔªËØ:¡¡Èç:¡¡var xx = document.getElementsByTagName("div");
src="imgs/1.png"/><br> <button id="btn1" type="button" value="
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> * { margin: 0; padding: 0; } #outer { width: 500px; /*ÉèÖÃÉϱ߾à50px ˮƽ¾ÓÖÐ*/ margin: 50px auto; /*ÉèÖñ߿ò*/ padding: 10px; background-color: greenyellow; /*ÉèÖÃÎı¾¾ÓÖÐ*/ text-align: center; }
img { width: 500px; } </style>
<script>
¡¡¡¡¡¡¡¡¡¡//btn Ϊ°´Å¥id clickEventFunction Ϊµã»÷ºóÖ´ÐеIJÙ×÷º¯Êý function addClick(btn, clickEventFunction) { var myButton = document.getElementById(btn); myButton.onclick = clickEventFunction; }; window.onload = function () { (function () { var pics = ["imgs/1.png", "imgs/2.png", "imgs/3.png"]; var index = 0; showPicNum(index); var img = document.getElementsByTagName("img")[0]; // var btn1 = document.getElementById("btn1"); var btn2 = document.getElementById("btn2"); addClick("btn1", function () { index--; if (index <= -1) { index = pics.length - 1; } console.log(index + " ----- "); img.src = pics[index]; showPicNum(index); }); addClick("btn2", function () { index++; if (index >= pics.length) { index = 0; } console.log(index + " ++++++++ "); img.src = pics[index]; showPicNum(index); }); // // btn1.onclick = function () { // index --; // if(index <= -1){ // index = pics.length - 1; // } // console.log(index + " ----- "); // img.src = pics[index]; // showPicNum(index); // }; // btn2.onclick = function () { // index ++; // if(index >= pics.length){ // index = 0; // } // console.log(index + " ++++++++ "); // img.src = pics[index]; // showPicNum(index); // }; console.log(index); /** * չʾµ±Ç°Í¼Æ¬ÎªµÚ¼¸ÕÅ * @param index µ±Ç°Í¼Æ¬Ë÷Òý */ function showPicNum(index) { var descrs = document.getElementById("discs"); descrs.innerText = "Ò»¹²" + pics.length + "ÕÅͼƬ,µ±Ç°µÚ" + ++index + "ÕÅ"; } }()) }; </script> </head> <body> <div id="outer"> <p id="discs"></p> <img src="imgs/1.png"/><br> <button id="btn1" type="button" value="ÉÏÒ»ÕÅ">ÉÏÒ»ÕÅ</button> <button id="btn2" type="button" value="ÏÂÒ»ÕÅ">ÏÂÒ»ÕÅ</button> </div> </body> </html>
¡¡¡¡ÎĵµÄ¿Â¼:¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡Ð§¹ûÈçÏÂ:
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
ÉÏÒ»ÕÅ">ÉÏÒ»ÕÅ</button> <button id="btn2" type="button" value="ÏÂÒ»ÕÅ">ÏÂÒ»ÕÅ</button></div></body></html>
±êÇ©£º
°æȨÉêÃ÷£º±¾Õ¾ÎÄÕ²¿·Ö×ÔÍøÂ磬ÈçÓÐÇÖȨ£¬ÇëÁªÏµ£ºwest999com@outlook.com
Ìرð×¢Ò⣺±¾Õ¾ËùÓÐתÔØÎÄÕÂÑÔÂÛ²»´ú±í±¾Õ¾¹Ûµã£¬±¾Õ¾ËùÌṩµÄÉãÓ°ÕÕƬ£¬²å»£¬Éè¼Æ×÷Æ·£¬ÈçÐèʹÓã¬ÇëÓëÔ×÷ÕßÁªÏµ£¬°æȨ¹éÔ×÷ÕßËùÓÐ
ÉÏһƪ£º°Ù¶ÈµØͼ¹öÂÖËõ·Åʱ²úÉúλÖÃÆ«ÒÆ ÎÊÌâ
ÏÂһƪ£ºcanvas »Ê±ÖÓ »á¶¯ßÏ
- javascriptÃæÏò¶ÔÏóÈëÃÅ»ù´¡Ïêϸ½éÉÜ 2020-03-29
- JavaScriptº¯Êý±í´ïʽÏê½â¼°ÊµÀý 2020-03-25
- ÈçºÎÓÃjavascriptÁ¬½ÓaccessÊý¾Ý¿â 2020-03-20
- jsÖÐÈ¥µô×Ö´®×óÓÒ¿Õ¸ñ 2020-03-20
- JavascriptÖеľµä¼¼ÇÉ 2020-03-20
IDC×ÊѶ£º Ö÷»ú×ÊѶ ×¢²á×ÊѶ ÍйÜ×ÊѶ vps×ÊѶ ÍøÕ¾½¨Éè
ÍøÕ¾ÔËÓª£º ½¨Õ¾¾Ñé ²ß»®Ó¯Àû ËÑË÷ÓÅ»¯ ÍøÕ¾Íƹã Ãâ·Ñ×ÊÔ´
ÍøÕ¾ÁªÃË£º ÁªÃËÐÂÎÅ ÁªÃ˽éÉÜ ÁªÃ˵ãÆÀ Íø׬¼¼ÇÉ
ÐÐÒµ×ÊѶ£º ËÑË÷ÒýÇæ ÍøÂçÓÎÏ· µç×ÓÉÌÎñ ¹ã¸æ´«Ã½
ÍøÂç±à³Ì£º Asp.Net±à³Ì Asp±à³Ì Php±à³Ì Xml±à³Ì Access Mssql Mysql ÆäËü
·þÎñÆ÷¼¼Êõ£º Web·þÎñÆ÷ Ftp·þÎñÆ÷ Mail·þÎñÆ÷ Dns·þÎñÆ÷ °²È«·À»¤
Èí¼þ¼¼ÇÉ£º ÆäËüÈí¼þ Word Excel Powerpoint Ghost Vista QQ¿Õ¼ä QQ FlashGet ѸÀ×
ÍøÒ³ÖÆ×÷£º FrontPages Dreamweaver Javascript css photoshop fireworks Flash
³ÌÐòÉè¼Æ£º Java¼¼Êõ C/C++ VB delphi
- Photoshop»æÖÆÁ¢Ìå·ç¸ñµÄ΢Ц±íÇé
- PSÎÄ×ÖÌØЧ½Ì³Ì£ºÖÆ×÷¹«Â·ÉϸöÐÔµÄÍ¿Ñ»
- PhotoshopÉè¼Æ¾í±ßЧ¹ûµÄ±äÐνð¸ÕµçÓ°
- PSÉ«²ÊÐÞ¸´½Ì³Ì£ºÀûÓÃÉ«½×¹¤¾ß¿ìËÙ¸øºì
- PS°ë͸Ã÷ÎïÌå¿Ùͼ£ºÀûÓÃͨµÀÑ¡Çø¹¤¾ß¿Ù
- PSº£±¨Éè¼Æ¼¼Çɽ̳̣ºÑ§Ï°ÖÆ×÷¸öÐԵč
- PSͼƬÌØЧÖÆ×÷½Ì³Ì£ºÑ§Ï°¸øÌúËþͼƬÖÆ
- ѧϰÓÃphotoshop°Ñ»ë×ǵĺ£Ë®ÕÕƬºóÆÚ
- PS¹Å·çÕÕƬ½Ì³Ì£º¸ø¹Å·çÃÀÅ®´òÔì³öÅ®ÏÀ
- PS¸öÐÔÈËÎﺣ±¨ÖÆ×÷£ºÉè¼Æ´´ÒâʱÉеIJ£
- ÓÃjavascriptʵÏÖBase64±àÂë
- ¡¾ÔËÐдíÎó¡¿Uncaught DOMException: B
- socket.io ³öÏÖµÄWebSocket is closed
- charles×¥°ü³öÏÖÂÒÂë SSL Proxying no
- ES6 require ( ·¾¶±äÁ¿ ) Ïà¹ØʹÓ÷½
- echartsÔÚµØͼÉÏ»æÖÆÉ¢µãͼ£¨ÈÎÒâµã£©
- NuxtÏîÄ¿´î½¨µ½·¢²¼²¿Êð
- Ê¡ÊÐÇøÈý¼¶Áª¶¯ÏÂÀÁÐ±í£¬»ñÈ¡µØÇø±àºÅ
- ×îÈ«Ç°¶Ë×ÊÔ´»ã×Ü
- layui table±í¸ñ ±íÍ·ÓëÄÚÈÝÁдíλÎÊ