Ver Mensaje Individual
  #8 (permalink)  
Antiguo 19/05/2009, 13:57
Avatar de zerokilled
zerokilled
Javascripter
 
Fecha de Ingreso: abril-2009
Ubicación: Isla del Encanto, La Borinqueña [+>==]
Mensajes: 8.050
Antigüedad: 15 años, 1 mes
Puntos: 1485
Respuesta: Problema con detachEvent

justo lo que ya venia diciendo. produce error type mismatch porque esta utilizando un string para remover el evento. no le veo el uso de generar un string a base de la funcion. el siguiente codigo es una modificacion funcional.

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