Pregunta

I'm trying to get the type of change of an element.

<input type="text" onchange="fn()"/>

<script>

function fn() {
    if (event.isKeyPress) 
        // do something
    else if (event.isClick)
        //do something else

</script>

So in full, I'm changing a text field, then to change, the user has to unfocus the field and change its contents. I want to find the manner at which it was unfocused (e.g. by tab or click). Is this possible?

NOTE: I am using jQuery.

¿Fue útil?

Solución

If you put a keydown event on your input, you can trig the focusout event if the pressed key is "tab" and do what you want. Else the focusout will be triggered by a clic.

Otros consejos

$('input').focus(function(){

   // something..

}).change(function(){ // or keyup

   // do something awesome

}).focusout(function(){

  // that's it

});
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top