Ver Mensaje Individual
  #7 (permalink)  
Antiguo 19/05/2009, 13:34
Avatar de pato12
pato12
 
Fecha de Ingreso: septiembre-2007
Ubicación: Salta
Mensajes: 1.620
Antigüedad: 17 años, 4 meses
Puntos: 101
Respuesta: Problema con detachEvent

Hola,
Este es un ejemplo:
Código javascript:
Ver original
  1. <script type="text/javascript">
  2. <!--
  3. function $(id){return document.getElementById(id);}
  4. function alertar(){
  5.     alert('Si!');
  6. }
  7. function detener(){
  8.     removeEvent.call($('prueba'),'click',alertar);
  9. }
  10. var addEvent=function(type, fn ) {
  11.             if ( this.addEventListener ) {
  12.                 this.addEventListener( type, fn, false );
  13.             } else if(this.attachEvent){
  14.                 var _this=this;
  15.                 var f= function(){fn.call(_this,window.event);};
  16.                 this.attachEvent( 'on'+type, f);
  17.                 this[fn.toString()+type]=f;
  18.             }else{
  19.                 this['on'+type]=fn;
  20.             }
  21.         };
  22. var removeEvent=function(evType,fn){
  23.             if(this.removeEventListener){
  24.                 this.removeEventListener(evType, fn, false);
  25.             }else if (this.detachEvent){
  26.                 this.detachEvent("on"+evType, this[fn+evType+'n']);
  27.                 this[fn+evType+'n']=null;
  28.             }else{
  29.                 this['on'+evType]=function(){};
  30.             }
  31.         };
  32.         onload=function(){
  33.             addEvent.call($('prueba'),'click',alertar);
  34.             addEvent.call($('prueba'),'mouseout',detener);
  35.         };
  36. -->
  37. </script>
  38. <div id="prueba" style="background-color:#CCCCCC; width:50px; height:50px;">Click!</div>
Gracias
Salu2
__________________
Half Music - www.halfmusic.com