admin管理员组文章数量:1289542
Im using the MVC 2 framwork and have added some javascript for expanding divs. It works fine in firefox, chrome, opera and safari but not in internet explorer. I get an 'Object Expected' Error. Here is my code
the jquery import is in the site.master file
<head runat="server">
<title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src=".5/jquery.min.js" charset="utf-8"></script>
The Javascript, in the mvc view: the test alert es up in IE but test2 doesn't.
<script type="text/javascript">
alert("test");
$(document).ready(function () {
alert("test2");
$(".expandingcontent").hide();
$(".divexpand").click(function () {
var divID = "#" + $(this).attr("id").substring(6);
if ($(divID).is(":hidden")) {
$(divID).slideDown("slow");
} else {
$(divID).hide();
}
});
});
</script>
Ive tried placing the javavscript at the beging of the page, at the end nothing seems to work. Ive also tried using a timeout but no success there either. I'm using IE 8, any help is very much appreciated Thanks!
Im using the MVC 2 framwork and have added some javascript for expanding divs. It works fine in firefox, chrome, opera and safari but not in internet explorer. I get an 'Object Expected' Error. Here is my code
the jquery import is in the site.master file
<head runat="server">
<title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis./ajax/libs/jquery/1.5/jquery.min.js" charset="utf-8"></script>
The Javascript, in the mvc view: the test alert es up in IE but test2 doesn't.
<script type="text/javascript">
alert("test");
$(document).ready(function () {
alert("test2");
$(".expandingcontent").hide();
$(".divexpand").click(function () {
var divID = "#" + $(this).attr("id").substring(6);
if ($(divID).is(":hidden")) {
$(divID).slideDown("slow");
} else {
$(divID).hide();
}
});
});
</script>
Ive tried placing the javavscript at the beging of the page, at the end nothing seems to work. Ive also tried using a timeout but no success there either. I'm using IE 8, any help is very much appreciated Thanks!
Share Improve this question asked Mar 25, 2011 at 9:30 WillMcKillWillMcKill 3902 gold badges6 silver badges13 bronze badges 7- On what line the error occurs? Do you see both alerts? – Shadow Wizzard Commented Mar 25, 2011 at 9:35
- maybe the jQuery JavaScript file is not loaded at the time. so you need to ensure that your script is executed after the jquery file is loaded. – Alex Pacurar Commented Mar 25, 2011 at 9:36
- There has to be something else in your HTML. Because this code works just fine in IE... – Yngve B-Nilsen Commented Mar 25, 2011 at 9:36
- Does the test2 appear in other browser? – Jan Zyka Commented Mar 25, 2011 at 9:38
- Theres nothing other than a few divs, it is running on https though, could that have something to do with it? – WillMcKill Commented Mar 25, 2011 at 9:39
4 Answers
Reset to default 3Your reference to Google CDN resource is wrong, especially if your site is using SSL.
Change your reference like this and it should work.
<script type="text/javascript" src="//ajax.googleapis./ajax/libs/jquery/1.5/jquery.min.js"></script>
Its because,
It’s not exactly light reading, but section 4.2 of RFC 3986 provides for fully qualified URLs that omit protocol (the HTTP or HTTPS) altogether. When a URL’s protocol is omitted, the browser uses the underlying document’s protocol instead.
Dave Ward explains it more: Cripple the Google CDN’s caching with a single character
P.S: Its better to use Google CDN, together with a local fallback resource in case CDN fails to load
It might be caused by it not being able to load the jquery.js? Try downloading it and putting it as a local resource.
Make sure to include the jquery script file before you execute the $(document).ready function.
In my case, I had an extraneous console.log in the JS and it quietly broke in IE. It was confusing because when I enabled the IE developer tools it magically started working. Anyway, check that, too.
本文标签: javascriptjquery quot(document)ready(function () quot isn39t working in IEStack Overflow
版权声明:本文标题:javascript - jquery "$(document).ready(function () {" isn't working in IE - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741411239a2377246.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论