开发者

IE6: jQuery change event assignment to controls

开发者 https://www.devze.com 2022-12-14 04:57 出处:网络
So I have my nifty function that detects changes for me in a form: function EnableChangeDetection(eForm) {

So I have my nifty function that detects changes for me in a form:

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 y开发者_JAVA百科ou don't need it any more.
            $("#" + eForm + " :input")
                .unbind("change");
        });
}

The problem is that this change functions fires inconsistently for non textbox inputs (checkboxs and radio buttons) in IE. Works fine everywhere else of course...


Here's my workaround that's been working...

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

精彩评论

暂无评论...
验证码 换一张
取 消