Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [HTML][JavaScript]jak zrobic pętle, jak zrobić pętle
Mastersieciweb
post
Post #1





Grupa: Zarejestrowani
Postów: 84
Pomógł: 0
Dołączył: 14.10.2013

Ostrzeżenie: (0%)
-----


witam, mam problem bo nie wiem jak zrobić pętle czy funkcje dzięki której nie musiałbym wypisywać po kolei moich obrazków tylko tak jakby to wszystko było klonowane tyle razy ile ja chce i funkcja onmouseover i onmouseout działała w każdym z osobno:) da sie tak?(IMG:style_emoticons/default/smile.gif)

  1.  
  2. <title>fgg</title>
  3.  
  4. <img src="maggie.jpg" id="1">
  5. <img src="maggie.jpg" id="2">
  6. <img src="maggie.jpg" id="3">
  7. <img src="maggie.jpg" id="4">
  8. <img src="maggie.jpg" id="5">
  9.  
  10.  
  11.  
  12. var nazwy = new Array('maggie.jpg', 'kate.jpg', 'roxana.jpg')
  13. var obr = [];
  14.  
  15. for (x=0; x<nazwy.length; x++) {
  16.  
  17. obr[x] = new Image();
  18.  
  19. obr[x].alt= nazwy[x];
  20.  
  21. }
  22.  
  23.  
  24.  
  25. document.getElementById('1').onmouseover = function() {
  26.  
  27. this.src = obr[1].alt;
  28.  
  29. }
  30.  
  31.  
  32. document.getElementById('1').onmouseout = function() {
  33.  
  34. this.src = obr[0].alt;
  35.  
  36. }
  37.  
  38. document.getElementById('2').onmouseover = function() {
  39.  
  40. this.src = obr[1].alt;
  41.  
  42. }
  43.  
  44.  
  45. document.getElementById('2').onmouseout = function() {
  46.  
  47. this.src = obr[0].alt;
  48.  
  49. }
  50.  
  51. document.getElementById('3').onmouseover = function() {
  52.  
  53. this.src = obr[1].alt;
  54.  
  55. }
  56.  
  57.  
  58. document.getElementById('3').onmouseout = function() {
  59.  
  60. this.src = obr[0].alt;
  61.  
  62. }
  63.  
  64. document.getElementById('4').onmouseover = function() {
  65.  
  66. this.src = obr[1].alt;
  67.  
  68. }
  69.  
  70.  
  71. document.getElementById('4').onmouseout = function() {
  72.  
  73. this.src = obr[0].alt;
  74.  
  75. }
  76.  
  77. document.getElementById('5').onmouseover = function() {
  78.  
  79. this.src = obr[1].alt;
  80.  
  81. }
  82.  
  83.  
  84. document.getElementById('5').onmouseout = function() {
  85.  
  86. this.src = obr[0].alt;
  87.  
  88. }
  89.  
  90. </body>
  91. </html>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Mastersieciweb
post
Post #2





Grupa: Zarejestrowani
Postów: 84
Pomógł: 0
Dołączył: 14.10.2013

Ostrzeżenie: (0%)
-----


z jakiś nieznanych przyczyn nie działa mi ta funkcja.. a da sie to napisać w JS a nie PHP? jeśli chodzi o tematy które wstawiłem to tylko dlatego, że jak już ktoś odpisał w nim to nikt dalej nie kontynuował ze mną rozmowy na ten temat.. ludzie wchodzą tylko na te nowe tematy..
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 27.12.2025 - 19:10