1

I have a simple function on click that toggles a div. It checks the classes to determine if it should remove the 'hilighted' state classes.

This fails to remove the holdhilite class:

function togglediv(id){
    //alert('toggle id= '+id);
    $("#"+id).toggle("fast");
    if(window.location.hash.split("#")[1]==justtheid(id)){
        var scr = document.body.scrollTop;
        window.location.href = '#';
        document.body.scrollTop = scr;          
    }       
    var trid = "tr_"+justtheid(id);
    if($("#"+trid).attr('class')=='holdhilight rowhover'){
        $("#"+trid).removeClass('holdhilight');         
    }
    else{
        $("#"+trid).addClass('holdhilight');            
    }
}

On the other hand, this works 100%:

function togglediv(id){
    alert('toggle id= '+id);
    $("#"+id).toggle("fast");
    if(window.location.hash.split("#")[1]==justtheid(id)){
        var scr = document.body.scrollTop;
        window.location.href = '#';
        document.body.scrollTop = scr;          
    }       
    var trid = "tr_"+justtheid(id);
    if($("#"+trid).attr('class')=='holdhilight rowhover'){
        $("#"+trid).removeClass('holdhilight');                         
    }
    else{
        $("#"+trid).addClass('holdhilight');            
    }
}

Note the only difference is that alert being uncommented (i don't even want to tell you how long it took me to figure out this was the issue... lol)

So, what's the deal? why does waiting/clicking ok on the alert allow the class=='holdhilight rowhover' to match but when no alert, it does not (even though an alert in this spot says it DOES indeed match, but once the alert is in place, it works again... lol)

I've waiting in my browser 30 seconds before trying to close it, and that did nothing to fix it. It's not the script taking forever to run.

This is all wrapped in a ready() function anyway.

I'm in an ie8-specific enviro (intranet) using the latest 1.9

4

1 回答 1

0

我终于通过使用动作处理程序作为一个函数来完成其他工作。这应该很明显,我觉得回答它很愚蠢,但是嘿,也许它可以帮助其他人。

$('#'+id).toggle('fast', function() {
//all the hash location stuff here will fire after the toggle is done. 
});
于 2013-02-14T23:29:01.183 回答