Bubble event and onblur event

I am writing a script form confirmation and would like to confirm the correctness of this field with its onblur event. I would also like to use the bubbling event, so I don’t need to apply the onblur event to each individual field of the form. Unfortunately, the onblur event does not bubble. Just wondering if anyone knows about an elegant solution that can give the same effect.

+3
source share
5 answers

ppk has a technique for this, including the necessary workarounds for IE: http://www.quirksmode.org/blog/archives/2008/04/delegating_the.html

+2
source

( ) , , focusout IE:

if (myForm.addEventListener) {
    // Standards browsers can use event Capturing. NOTE: capturing 
    // is triggered by virtue of setting the last parameter to true
    myForm.addEventListener('blur', validationFunction, true);
}
else {
    // IE can use its proprietary focusout event, which 
    // bubbles in the way you wish blur to:
    myForm.onfocusout = validationFunction;
}

// And of course detect the element that blurred in your handler:
function validationFunction(e) {
    var target = e ? e.target : window.event.srcElement;

    // ...
}

. http://www.quirksmode.org/blog/archives/2008/04/delegating_the.html

+8

' , Bubble .thanks.

+2

onblur, addEventListener() useCapture false. :

yourFormInput.addEventListener('blur', yourFunction, false);

Firefox 51 onfocusout. onfocusout onblur.

0

aa, onblur ,

-2
source

Source: https://habr.com/ru/post/1719387/


All Articles