2009-12-18 2 views
1

J'ai donc ma nifty fonction qui détecte les changements pour moi sous une forme:IE6: affectation d'événement de changement jQuery aux contrôles

function EnableChangeDetection(eForm) { 

    // One of the nice benefits of this change detection is that we don't have 
    // to keep an additional array of previous values to compare. Also we 
    // don't have to worry about applying global unformatting for comparison 
    // and formatting back 

    // For each input control 
    $("#" + eForm + " :input") 
    // Add a change event that will trigger if the form has been changed 
     .one("change", function() { 

      $.jGrowl("Change detected..."); 

      // Flag the form with an IsDirty class 
      $("#" + eForm) 
       .attr("class", "IsDirty") 

      // Now remove the event handler from all the elements 
      // since you don't need it any more. 
      $("#" + eForm + " :input") 
       .unbind("change"); 
     }); 
} 

Le problème est que ce changement des fonctions incendies incohérente pour les entrées non TextBox (checkboxs et de la radio boutons) dans IE. Fonctionne très bien partout ailleurs bien sûr ...

+3

explication détaillée de PPK est ici: http://www.quirksmode.org/dom/events/change .html –

+0

Et je vous conseille d'oublier IE6. Avoir un script qui indique à l'utilisateur de mettre à jour vers un navigateur IE plus récent. Je ne considère plus IE6 quand je développe des pages Web :) – Steven

+0

Je pense que vous n'avez pas besoin d'appeler 'unbind'. C'est la contrepartie de «lier». Vous utilisez 'one' qui est déclenché une seule fois de toute façon. – RamboNo5

Répondre

0

Voici mon solution qui a travaillé ...

function EnableChangeDetection(eForm) { 

    // One of the nice benefits of this change detection is that we don't have 
    // to keep an additional array of previous values to compare. Also we 
    // don't have to worry about applying global unformatting for comparison 
    // and formatting back 

    // IE6 Workaround: onchange events need a blur event to properly fire 
    $("#" + eForm + " :input[type='checkbox'], input[type='radio']") 
     .one("click", function() { $(this).get(0).blur(); }) 

    // For each input control 
    $("#" + eForm + " :input") 
     // Add a change event that will trigger if the form has been changed 
     .one("change", function() { 

      $.jGrowl("Change detected..."); 

      // Flag the form with an IsDirty class 
      $("#" + eForm) 
       .attr("class", "IsDirty") 

      // Now remove the event handler from all the elements 
      // since you don't need it any more. 
      $("#" + eForm + " :input") 
       .unbind("change"); 
     }); 
} 
Questions connexes