🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.javascript
Article #50244

Re: dlaczego firstChild oraz childNodes[0] mam undefined?

#50244
From: Jivanmukta
Date: Sun, 19 Mar 2017 15:47
49 lines
1781 bytes
zpksoft wrote:
>> A poza tym, zrezygnuj z onfocus i onblur inline i skorzystaj z delegacji
>> zdarzeń (event delegation):
>>
>> https://bfkot.wordpress.com/2010/09/02/event-delegation-delegowane-nasluchy-czyli-wydarzenia-w-delegacji-czesc-1/
>>
>> --
>> Cezary Tomczyk
>> https://www.aslint.org/ - walidacja Accessibility
>> Blokowanie automatycznego odtwarzania video na gazeta.pl w Google
>> Chrome: https://goo.gl/0kCRLS
>
> Dodam jeszcze że niezbyt inteligentny jest ten kod. Po co tak motać prosty
> sznurek?
>
> Przecież wystarczy napisać:
>
>   document.onclick = function(e){
>
>   e = e || window.event;
>   var t = e.target || e.srcElement;
>   n=t.id || t.className;
>   if (!n) return;
> //i teraz obsługa naszej aplikacji:
>
> if (n=='id_diva1') {...}
> else if (n=='id_elementu_span1') {...}
> else ...

Zrobiłem tak:

function setFocusAndBlur() {
	var i, sel;
	sel = document.querySelectorAll("fieldset input");
	for (i = 0; i < sel.length; i++) sel[i].onfocus = onFocusElement;
	sel = document.querySelectorAll("fieldset input");
	for (i = 0; i < sel.length; i++) sel[i].onblur = onBlurElement;
	sel = document.querySelectorAll("fieldset select");
	for (i = 0; i < sel.length; i++) sel[i].onfocus = onFocusElement;
	sel = document.querySelectorAll("fieldset select");
	for (i = 0; i < sel.length; i++) sel[i].onblur = onBlurElement;
	sel = document.querySelectorAll("fieldset textarea");
	for (i = 0; i < sel.length; i++) sel[i].onfocus = onFocusElement;
	sel = document.querySelectorAll("fieldset textarea");
	for (i = 0; i < sel.length; i++) sel[i].onblur = onBlurElement;
	document.querySelector("#captcha").onfocus = onFocusElement;
	document.querySelector("#captcha").onblur = onBlurElement;
}

i mi działa. Problem zamknięty. Dzięki za pomoc.

Message-ID: <oam5le$19g0$1@gioia.aioe.org>
Path: polish.pugleaf.net!archive.newsdeef.eu!apf1.newsdeef.eu!news.usenet.farm!..!..!not-for-mail
References: <oaaiu9$jmk$1@news.icm.edu.pl> <oaauv5$1i7t$1@csiph.com> <5d210841-ac34-4a0b-9981-9fe8d5e61d4c@googlegroups.com>