jQuery $(document).ready() failing in IE6

前端 未结 12 1033
一向
一向 2020-12-06 11:50

I have the following code:

// Creates a timer to check for elements popping into the dom            
timer = setInterval(function ()
{          
    for (p i         


        
相关标签:
12条回答
  • 2020-12-06 12:10

    You could try the old skool way of checking whether the document is "ready"... Place the script just before the closing </body> tag - I believe it has the same effect as jQuery's 'ready' event - actually, it's probably quicker doing it this way.


    In my experience the "Object expected" error in IE6 shows up because of a syntax error - it's worth putting the script though JSlint, if you haven't already...

    0 讨论(0)
  • 2020-12-06 12:11

    Are you sure that jQuery is loaded? Try debugging with alerts like:

    alert(typeof $);
    

    You could also try a different syntax:

    $(function() {
         clearInterval(timer); 
    });
    

    Ok, so from your comment, the above doesn't help. The "object expected" error seems to occur with a syntax error in my experience. Is that the exact code you've got? If not, could you post it?

    0 讨论(0)
  • 2020-12-06 12:11

    I had the same issue, script error informing me that the object was undefined. I tried all the suggestions listed here with no avail. Only thing I did not consider was security, I had forgotten all about my forms authentication and turns out I forgotten about the authorisation on the scripts folder which was denying access to the jQuery libraries!!!

    Hope this helps.

    0 讨论(0)
  • 2020-12-06 12:18

    The DateTime picker worked just fine on my local XP test, but it failed "Object Expected" once deployed on the server. After 2 days of being persistent, this is how I solved my problem, adding the Url.Content around the path of the Javascript!

    <script src="<%= Url.Content("~/Scripts/jquery-1.4.1.min.js") %>" type="text/javascript"></script>
    
    <script src="<%= Url.Content("~/Scripts/ui/minified/jquery.ui.core.min.js") %>" type="text/javascript"></script>  
    <script src="<%= Url.Content("~/Scripts/ui/minified/jquery.ui.datepicker.min.js") %>" type="text/javascript"></script>
    
    0 讨论(0)
  • 2020-12-06 12:19

    $(document).ready() tells you when the dom is ready, but not all assets are necessarily done coming in.

    If you want to make sure all the assets are actually done loading, use $(window).load() instead. The most common use for this is to make sure that images are done loading, but it may work for your script problem as well.

    0 讨论(0)
  • 2020-12-06 12:22

    I don't think that you should really be polling for elements the way you are.

    The document ready event calls as soon as the browser has loaded enough for you to be able to manipulate the page, so you should just do your DOM processing in the $(document).ready() block.

    0 讨论(0)
提交回复
热议问题