0

I can't seem to get a keyup event to trigger in Safari 5.0.6 on Mac Os X 10.5.8

<textarea id="edit" cols="25" rows="5"></textarea>

document.getElementById("edit").addEventListener('keyup', function () {
    console.log("hi");
});

http://jsfiddle.net/barra/8Fy72/4/

Works fine in Firefox. I've also tried alert instead of console.log with no luck.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Baz
  • 12,713
  • 38
  • 145
  • 268

1 Answers1

1

Consider cross-browser event handling if you are going to support multiple browsers.

function addEvent( obj, type, fn ) {
  if ( obj.attachEvent ) {
    obj['e'+type+fn] = fn;
    obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
    obj.attachEvent( 'on'+type, obj[type+fn] );
  } else
    obj.addEventListener( type, fn, false );
}
function removeEvent( obj, type, fn ) {
  if ( obj.detachEvent ) {
    obj.detachEvent( 'on'+type, obj[type+fn] );
    obj[type+fn] = null;
  } else
    obj.removeEventListener( type, fn, false );
}

Taken from http://ejohn.org/projects/flexible-javascript-events/

talabes
  • 5,344
  • 2
  • 22
  • 27