In what order are events triggered when a radio button is pressed?

I know this is different from browsers; for example, If I attach a function to the onclick and onchange event of the switch, then click on it, Chrome will start onchange, then onclick, and Firefox will do the opposite.

Is there any resource that knows about this that violates this browser fire order?

+5
source share
1 answer

Here's a JSFiddle that will tell you if you run it in every browser:

http://jsfiddle.net/BUkHz/

<label for="myRadio">Radio Button</label><input type="radio" name="myRadio" id="myRadio"/>
<label for="myRadio">Radio Button 2</label><input type="radio" name="myRadio" id="myRadio2"/>




var myRadio = document.getElementById('myRadio');
    var myRadio2 = document.getElementById('myRadio2');

    myRadio.addEventListener('change', interceptRadioEvent);
    myRadio.addEventListener('click', interceptRadioEvent);
    myRadio2.addEventListener('change', interceptRadioEvent);
    myRadio2.addEventListener('click', interceptRadioEvent);

    function interceptRadioEvent(e){
        //do anything else you want to here...
        radioEventHandler(e);
    }

    function radioEventHandler(e){
        console.log(e.type);
    }

, , - , , : , , 'click' , , .

, .

Mac:

Chrome:

Safari:

IOS, (6):

0

All Articles