Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript] Sprawdzenie co wywołało zdarzenie
dariolee
post
Post #1





Grupa: Zarejestrowani
Postów: 81
Pomógł: 0
Dołączył: 18.04.2007

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


Witam,
Jak sprawdzić jaki element wywołał zdarzenie ?

  1. <div style="background:green" onmouseout="alert('poza');"><p style="background:red">fdsafdasfdasfdasfadfdasfdsa</p>
  2. <p style="background:blue">fdsafdafdasfdsafdasfasdfdasfdas</p></div>

I teraz jak sprawdzić czy alert wywołał div czy ktoryś ze znaczników <p> w tym divie??
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
dariolee
post
Post #2





Grupa: Zarejestrowani
Postów: 81
Pomógł: 0
Dołączył: 18.04.2007

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


W końcu znalazłem ciekawe rozwiązanie:

Kod
function catchevent() {
eventSrcID=(event.srcElement)?event.srcElement.id:'undefined';
eventtype=event.type;
status=eventSrcID+' has received a '+eventtype+' event.';
}


pokazujące id elementu nad którym jest kursor myszki z tym, że jest to pod IE.
Próbowałem przerobic to na FF zamieniając srcElement na target ale nie poszło. Gdzie popełniłem błąd ? W FF w konsoli błędów pokazuje mi, że event nie jest zdefiniowany.

Kod
function catcheventFireFox() {
eventSrcID=(event.target)?event.target.id:'undefined';
eventtype=event.type;
status=eventSrcID+' has received a '+eventtype+' event.';
}

próbowałem i tak
Kod
function catcheventFireFox(event) {
var e = event || window.event;
eventSrcID=(e.target)?e.target.id:'undefined';
eventtype=e.type;
status=eventSrcID+' has received a '+eventtype+' event.';
}
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: 16.10.2025 - 07:19