Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Problem z podświetlaniem (JS)
LazyDragon
post
Post #1





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 8.05.2012

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


Witam!
Jestem w miarę początkujący w js i aktualnie borykam się z małym problemem. Mianowicie chodzi mi o następujący efekt:

Jeśli otwartą mamy podstronę index.html - powinien się podświetlać home, jesli services.html - services no i tak dalej...

Oto mój niedziałający kod (ma wcięcia ale zrównuje tu do lewej... Wrzucam poniżej obrazek dla każdego komu łatwiej ogarnąć wizualnie):
Cytat
function hoover() {
if(window.location.href.indexOf("index.html")){
document.getElementById("home").src = "images/home_hover.png";
}
else{
if(window.location.href.indexOf("services.html")){
document.getElementById("services").src = "images/services_hover.png";
}
else{
if(window.location.href.indexOf("offert.html")){
document.getElementById("offert").src = "images/offert_hover.png";
}
else{
if(window.location.href.indexOf("gallery.html")){
document.getElementById("gallery").src = "images/gallery_hover.png";
}
else{
if(window.location.href.indexOf("about.html")){
document.getElementById("about").src = "images/about_hover.png";
}
else{
if(window.location.href.indexOf("contact.html")){
document.getElementById("contact").src = "images/contact_hover.png";
}
}
}
}
}
}

}



w html rozwiązałem sprawę bardzo prosto:
Cytat
<body onLoad="hoover()">

Czemu to nie działa... Pomożecie?
Jestem otwarty na alternatywy i chętnie się czegoś naucze smile.gif

Ten post edytował LazyDragon 8.05.2012, 10:09:17
Go to the top of the page
+Quote Post
rocktech.pl
post
Post #2





Grupa: Zarejestrowani
Postów: 587
Pomógł: 131
Dołączył: 8.02.2010

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


Witam.

Tylko i wylącznie Firebug lub DragonFly. Uwierz mi, że czegoś się nauczysz.


--------------------
Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo. --Brian Moore

I never go looking for a sucker. I look for a Champion and make a sucker of of him. --Amarillo Slim


Home-made : js-gui-classes | Accordion | Tabs | Carousel / php-sms-classes | Obsługa bramki SMS MultiInfo | Obsługa bramki SMS Mobiltek
Go to the top of the page
+Quote Post
LazyDragon
post
Post #3





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 8.05.2012

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


O narzędziach później biggrin.gif
Póki co chciałbym się dowiedzieć dlaczego ten kod nie działa tongue.gif bo jak na moje oko niczego mu nie brak ; d
wydaje mi się, ze to window.location.href.indexOf("services.html") stanowi jedyny problem (?)

ps. dorzucam samą konstrukcję menu:
Cytat
<ul>
<li><a href="#"><img id="home" src="images/home.png" alt="Home" /></a></li>
<li><a href="#"><img id="services" src="images/services.png" alt="Services" /></a></li>
<li><a href="#"><img id="offert" src="images/offert.png" alt="Offert" /></a></li>
<li><a href="#"><img id="gallery" src="images/gallery.png" alt="Gallery" /></a></li>
<li><a href="#"><img id="about" src="images/about.png" alt="About" /></a></li>
<li><a href="#"><img id="contact" src="images/contact.png" alt="Contact" /></a></li>
</ul>


Ten post edytował LazyDragon 8.05.2012, 10:04:03
Go to the top of the page
+Quote Post
rocktech.pl
post
Post #4





Grupa: Zarejestrowani
Postów: 587
Pomógł: 131
Dołączył: 8.02.2010

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


Mówisz o narzędziach później, a gdybyś miał te narzędzia to wklepując w konsolę

[JAVASCRIPT] pobierz, plaintext
  1. window.location.href.indexOf("index.html")
[JAVASCRIPT] pobierz, plaintext


Otrzymałbyś wynik:

Kod
20


I wiedział że z twoim warunkiem jest coś nie tak i powinien wyglądać następująco.

[JAVASCRIPT] pobierz, plaintext
  1. if(window.location.href.indexOf("index.html") >= 0) ...
[JAVASCRIPT] pobierz, plaintext


Pozdrawiam.


--------------------
Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo. --Brian Moore

I never go looking for a sucker. I look for a Champion and make a sucker of of him. --Amarillo Slim


Home-made : js-gui-classes | Accordion | Tabs | Carousel / php-sms-classes | Obsługa bramki SMS MultiInfo | Obsługa bramki SMS Mobiltek
Go to the top of the page
+Quote Post
LazyDragon
post
Post #5





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 8.05.2012

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


Wielkie dzięki smile.gif będę musiał serio poogarniać coś ponad notatnik : D

Uwaga bump! Jeszcze jeden problem! ; d

Podświetlanie nie działa na IE

Gdzie leży problem?
Cytat
Line 47, Column 14: there is no attribute "onLoad"
<body onLoad="hoover()">

You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is often caused by incorrect use of the "Strict" document type with a document that uses frames (e.g. you must use the "Transitional" document type to get the "target" attribute), or by using vendor proprietary extensions such as "marginheight" (this is usually fixed by using CSS to achieve the desired effect instead).

This error may also result if the element itself is not supported in the document type you are using, as an undefined element will have no supported attributes; in this case, see the element-undefined error message for further information.

How to fix: check the spelling and case of the element and attribute, (Remember XHTML is all lower-case) and/or check that they are both allowed in the chosen document type, and/or use CSS instead of this attribute. If you received this error when using the <embed> element to incorporate flash media in a Web page, see the FAQ item on valid flash.


Validator twierdzi, że mam źle zdeklarowany dokument i strict (przecież mam Transitional) nie obsługuje oficjalnie czegoś takiego jak onLoad... ; d

Jak alternatywnie to zapisać nie używając onLoad lub na jaki typ dokumentu najlepiej się przestawić?
Aktualnie używam
Cytat
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">


Ten post edytował LazyDragon 8.05.2012, 11:24:02
Go to the top of the page
+Quote Post
rocktech.pl
post
Post #6





Grupa: Zarejestrowani
Postów: 587
Pomógł: 131
Dołączył: 8.02.2010

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


[JAVASCRIPT] pobierz, plaintext
  1. document.body.onload = hoover;
[JAVASCRIPT] pobierz, plaintext


--------------------
Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo. --Brian Moore

I never go looking for a sucker. I look for a Champion and make a sucker of of him. --Amarillo Slim


Home-made : js-gui-classes | Accordion | Tabs | Carousel / php-sms-classes | Obsługa bramki SMS MultiInfo | Obsługa bramki SMS Mobiltek
Go to the top of the page
+Quote Post
kamil4u
post
Post #7





Grupa: Zarejestrowani
Postów: 2 350
Pomógł: 512
Dołączył: 4.01.2009
Skąd: Wrocław / Świdnica

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


I ogólnie poczytaj o zdarzeniach( w JS to podstawa ): http://webhelp.pl/artykuly/obsluga-zdarzen-w-przegladarkach/


--------------------
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 22.08.2025 - 00:44