jQuery - Object Expected on IE and $(document).ready(function() {});

无人久伴 提交于 2019-12-19 11:28:04

问题


I have a page ([LINK REMOVED]) that works completely well in FireFox and Chrome, but for some reason I am getting an "Object Expected" error in most, if not all versions of IE.

The error occurs on the line

$(document).ready(function() {
    //^ Error occurs here ^
    ...
}

I am using jQuery Tools, which implements jQuery 1.4.2, as well as some additional stuff.

I've done some reading around. I've tried to put the ready function at the end of the code, right before the </body> tag - in addition, I've tried implementing a timer to let IE load before executing, and I can not shake this error.


回答1:


Here's one problem that can cause IE to choke where other browsers may not:

$('#' + resultDivName).animate({
  height: '300px', // <=== TRAILING COMMA
}, 500, function() {
  // Animation complete.
});  

Then, in your qtip call, you have:

target: 'popPart_WM300BP'

I believe target takes a jQuery DOM object, not a string. DebugBar points to this line as the cause of "object expected".

Finally, it looks like this version of jQuery Tools includes jQuery 1.4.2. Perhaps 1.4.3 or 1.4.4 would be worth a try.




回答2:


Could be the url you're using for jquery.tools. It is missing the http: part.

//cdn.jquerytools.org/1.2.5/jquery.tools.min.js

should be

http://cdn.jquerytools.org/1.2.5/jquery.tools.min.js




回答3:


If you are testing over a HTTPS connection, check if you are choosing view only the content that was delivered securely. If you choose YES maybe the scripts will not be loaded.




回答4:


Your $(document).ready and $(function(){..} methods are just fine - in fact when I fired up the Visual Studio debugger and attached to the page, those methods were firing as expected. The problem is that they are trying to call a function named initializePageMain() that doesn't exist for some reason. As to why that function doesn't seem to exist... I am not sure.

I would also try "fixing" the script tag that contains this code (sidenote: why isn't doToolTips defined in your index.js file?) to read like the rest of your script tags (get rid of the language element:

<script type="text/javascript"> ... </script>



回答5:


This is another gem that causes this error in IE

Math..random();

Those two dots (..) will ruin you.



来源:https://stackoverflow.com/questions/4199577/jquery-object-expected-on-ie-and-document-readyfunction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!