2009-12-18 27 views
1

所以,我有我的,檢測的變化,我在窗體漂亮的函數:IE6:jQuery的變更事件分配控制

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"); 
     }); 
} 

的問題是,這種變化的功能火災不一致的非文本框輸入(checkboxs和電臺按鈕)在IE中。做工精細其他地方當然...

+3

透徹的解釋是在這裏:http://www.quirksmode.org/dom/events/change .html – 2009-12-18 18:39:08

+0

我建議你忘記IE6。有一個腳本告訴用戶更新到一個更新的IE瀏覽器。當我開發網頁時,我從不考慮IE6 :) – Steven 2009-12-18 18:47:22

+0

我認爲你不需要調用'unbind'。這是'bind'的對應物。無論如何,你正在使用只有一次的「one」。 – RamboNo5 2009-12-18 19:00:43

回答

0

這裏是我的解決方法是一直工作...

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"); 
     }); 
} 
從PPK