🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: pl.comp.lang.javascript
4 messages
4 total messages Started by pawel2420 Fri, 22 Feb 2013 08:11
Dynamicznie dodawanie zdarzenia
#51273
Author: pawel2420
Date: Fri, 22 Feb 2013 08:11
11 lines
1279 bytes
Witam !

Załóżmy że na stronie mam obrazek:
<img id="abc" onclick="ocl(event);" ...
Podłączone ma on zdarzenie "onclick". Potrzebuję jednak dodać to 
zdarzenie dynamicznie (w zależności od przeglądarki). Nie bardzo wiem 
jak mam to zrobić prawidłowo. Próbowałem tak:
document.getElementById('abc').onclick = function(){ocl(this.event);};
ale nie przekazuje się do 'ocl' parametr (TypeError: event is undefined).

Paweł
Re: Dynamicznie dodawanie zdarzenia
#51274
Author: TOUDIdel
Date: Fri, 22 Feb 2013 08:58
8 lines
1123 bytes
W dniu 22.02.2013 09:11, pawel2420 pisze:
> document.getElementById('abc').onclick = function(){ocl(this.event);};

Spróbuj:
document.getElementById('abc').onclick = function(event){ocl(event);};

-- 
td
Re: Dynamicznie dodawanie zdarzenia
#51275
Author: pawel2420
Date: Fri, 22 Feb 2013 09:46
12 lines
1326 bytes
W dniu 2013-02-22 09:58, TOUDIdel pisze:
> W dniu 22.02.2013 09:11, pawel2420 pisze:
>> document.getElementById('abc').onclick = function(){ocl(this.event);};
>
> Spróbuj:
> document.getElementById('abc').onclick = function(event){ocl(event);};
>

Działa !!!
Bardzo dziękuję za pomoc.

Paweł
Re: Dynamicznie dodawanie zdarzenia
#51276
Author: Antek
Date: Tue, 09 Apr 2013 06:43
9 lines
1357 bytes
Ja bym raczej skorzystał z addEventListener

W dniu 2013-02-22 09:58, TOUDIdel pisze:
> W dniu 22.02.2013 09:11, pawel2420 pisze:
>> document.getElementById('abc').onclick = function(){ocl(this.event);};
>
> Spróbuj:
> document.getElementById('abc').onclick = function(event){ocl(event);};
>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads