javascript - What is the parameter to use for event? how do i know? -
element.onkeypress = function(e) { if(e.keycode) { element.keycode = e.keycode; } else { element.keycode = e.charcode; } }; also in java script , there also
<input onchange="a(event)"/> <script> function a(event) { alert(event.target.value); } </script> as parameter receiving, how know if must put event parameter instead of e? second example wont work if it's parameter other event aren't both javascript?
when bind event handler using on* property or addeventlistener, event object passed first argument. name usual when writing function expression or function declaration. normal restrictions on can name arguments apply (i.e. must valid identifier names). event, e , evt common names variable.
when bind event handler using on* attribute, writing function body (i.e. function (event) { , } implied. event object available in event variable.
Comments
Post a Comment