Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it L'avatar di agenti
    Registrato dal
    Feb 2002
    Messaggi
    2,427

    event handler con preventDefault

    Ciao A tuti,
    mi ritrovo in una situazione di questo tipo dato che non posso usare nessun framework:

    codice:
    var cb_addEventListener = function(obj, evt, fnc) {
        // W3C model
        if (obj.addEventListener) {
            obj.addEventListener(evt, fnc, false);
            return true;
        }
        // Microsoft model
        else if (obj.attachEvent) {
            return obj.attachEvent('on' + evt, fnc);
        }
        // Browser don't support W3C or MSFT model, go on with traditional
        else {
            evt = 'on'+evt;
            if(typeof obj[evt] === 'function'){
                // Object already has a function on traditional
                // Let's wrap it with our own function inside another function
                fnc = (function(f1,f2){
                    return function(){
                        f1.apply(this,arguments);
                        f2.apply(this,arguments);
                    }
                })(obj[evt], fnc);
            }
            obj[evt] = fnc;
            return true;
        }
        return false;
    };
    
    
    
     var b1 = function (e){
                   e.preventDefault();
                   return check_widget(data.label);
    
            }
    
            cb_addEventListener(button1,'click',b1);
    ottengo un errore
    sulla gestione dell'evento nel comando e.preventDefault();
    Non so come recuperare l'oggetto evento per definire il preventDefault
    2000 post e sono più vecchio di 4 anni...
    grazie a tutti....

  2. #2
    Utente di HTML.it L'avatar di agenti
    Registrato dal
    Feb 2002
    Messaggi
    2,427
    aggiungo altre info:

    il problema sembra risiedere su ie.
    su firefox il preventdefault viene accettato.
    2000 post e sono più vecchio di 4 anni...
    grazie a tutti....

  3. #3
    Utente di HTML.it L'avatar di agenti
    Registrato dal
    Feb 2002
    Messaggi
    2,427

    risolto

    function ie8SafePreventEvent(e){
    if(e.preventDefault){ e.preventDefault()}
    // else{e.stop()};

    e.returnValue = false;
    //e.stopPropagation();
    }

    basta usare questa funzione
    2000 post e sono più vecchio di 4 anni...
    grazie a tutti....

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.