jQuery 1.7.2无法在IE8中运行。适用于其他浏览器

时间:2012-08-09 12:53:10

标签: javascript jquery asp.net-mvc internet-explorer-8

SOLUTION 8/9/2012 9:54 EDT
令人尴尬的是,我们能够将问题追踪到浏览器设置。活动脚本已禁用。感谢所有发布的人。我很感激你的时间和努力。 ~~~~~~~~~~~~~~~~~~~~~~~~~~

我最近开始使用新的MVC3应用程序,我们正在使用jQuery 1.7.2。目前我们的代码适用于Chrome,Firefox和IE7& 9.不幸的是它在IE8中不起作用。我们尝试使用的jQuery函数(mouseover,mouseout,hover,click等)并不重要。

到目前为止,我已经尝试了以下但没有运气。

  • 使用jQuery和js文件的绝对路径引用
  • 将js代码直接移至_Layout.cshtml
  • 验证type =“text / javascript”
  • 将代码缩减为仅警报(“任何文本”);并在备用浏览器中验证
  • 添加背景色
  • 删除对“Menu.js”的引用,以测试Shared.js中的非常简单的代码是否有效

我正在尝试将.hover操作用于_ActionItems局部视图。这个jQuery是在Menu.js.我想如果我可以让它工作,其余的可能会有类似的解决方案,我可以弄清楚。

如果您还需要查看其他内容,请告诉我们。在此先感谢您的帮助。

_Layout.cshtml

@using eRecruitBoard.ExtensionMethods
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <title>@ViewBag.Title</title>
    <link href='http://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic' rel='stylesheet' type='text/css'/>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.7.2.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/Shared.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/Menu.js")" type="text/javascript"></script>
</head>
<body>
    <div class="wrapper">
            <div class="aboveHeader">
                <div class="aboveHeaderLeft">@Html.Partial("_ERBLogo")</div>

                <div class="aboveHeaderRight">
                    <div class="ERBESBButtons">@Html.Partial("_ERBESBButtons")</div>
                    <div class="welcome">@Html.Partial("_Welcome")</div>
                </div>
            </div>
            <div class="headerBar">
                <div class="headerActions">@Html.Partial("_ActionItems")</div>
                <div class="headerMenu">@Html.Action("Menu", "Menu")</div>
                <div class="headerTitle">@Html.Action("HeaderTitle","Segment")</div>
            </div>
        <div class="content">
            @RenderBody()
        </div>
        <div class="Push"></div>
  </div>  
    <div class="footerWrapper">
        <div class="footer">
            <div class="footerLeft"></div>
            <div class="footerRight"></div>
            <div class="footerRightContent">@Html.ActionLink("Privacy Policy", "PrivacyPolicy", "Home")</div>
            <div class="footerLeftContent">&copy; Copyright 2012 - All Rights Reserved</div>
        </div>
    </div>
</body>
</html>

_ActionItems.cshtml

@if (eRecruitBoard.WebLibrary.CommonFunctions.IsAuthenticated)
{
@Html.ImageActionLink("../../Images/Header/FavoriteIcon.png", "FavoritesIcon", "Add", "Favorites", null, null, new { @class = "over", title="Add to favorites", style="border:0;" })<text>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</text>
<img src="../../Images/Header/CalendarIcon.png" title="Schedule this report" alt="CalendarIcon" class="over"/><text>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</text>
<img src="../../Images/Header/EmailIcon.png" title="Email this report" alt="EmailIcon" class="over"/><text>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</text>
<img src="../../Images/Header/PrintIcon.png" title="Print" alt="PrintIcon" class="over"/>
}
else
{ 
}

Shared.js

// Hover image
$(document).ready(function () {
    $(function () {
        $("img.over").each(function () {
            var t = $(this);
            var src1 = t.attr("src"); // initial src
            var newSrc = src1.substring(0, src1.lastIndexOf(".")); // let's get file name without extension
            t.hover(function () {
                $(this).attr("src", newSrc + "Over." + /[^.]+$/.exec(src1)); //last part is for extension   
            }, function () {
                $(this).attr("src", newSrc + "." + /[^.]+$/.exec(src1)); //removing 'Over' from the name
            });
        });
    });
});

更新 - 我删除了menu.js代码,以便添加浏览器源代码。我现在专注于Shared.js代码,因为它很简单,即使完全删除Menu.js也不会导致任何操作。

浏览器源代码示例 - 请注意,这是我运行的测试之一,我将jQuery直接移到了页面上,然后添加了警报。无论如何,这也行不通。

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <title>eRecruitBoard</title>

    <link href='http://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic' rel='stylesheet' type='text/css'/>
    <link href="/Content/Site.css" rel="stylesheet" type="text/css" />
    <script src="/Scripts/jquery-1.7.2.js" type="text/javascript"></script>

    <script type="text/javascript"> 
// Hover image
$(document).ready(function () {
    $(function () {
$("#container").hover('',function(){ 
alert("Out"); 
});
    });
});


$(document).ready(function () {
    $(function () {
        $("img.over").each(function () {
            var t = $(this);
            var src1 = t.attr("src"); // initial src
            var newSrc = src1.substring(0, src1.lastIndexOf(".")); // let's get file name without extension
            t.hover(function () {
                $(this).attr("src", newSrc + "Over." + /[^.]+$/.exec(src1)); //last part is for extension   
            }, function () {
                $(this).attr("src", newSrc + "." + /[^.]+$/.exec(src1)); //removing 'Over' from the name
            });
        });
    });
});
</script>
</head>
<body>
    <div class="wrapper">

            <div class="aboveHeader">
                <div class="aboveHeaderLeft"><a href="/"><img alt="eRecruitBoard" src="../../Images/eRecruitBoardLogo.png" style="border:0;" /></a></div>

                <div class="aboveHeaderRight">
                    <div class="ERBESBButtons"><img src="../../Images/Header/ERBOn.png" alt="eRecruitBoard On"/><img src="../../Images/Header/ESBOff.png" alt="eScoreBoard Off"/>
</div>
                    <div class="welcome">Welcome Firstname Lastname&nbsp;&nbsp;&nbsp; 
<a href="/Admin/MyTeam">Admin</a>&nbsp;|&nbsp;
<a href="/Home/Logout">Logout</a></div>
                </div>
            </div>

            <div class="headerBar">
                <div class="headerActions"><a href="/Favorites/Add"><img alt="FavoritesIcon" class="over" src="../../Images/Header/FavoriteIcon.png" style="border:0;" title="Add to favorites" /></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<img src="../../Images/Header/CalendarIcon.png" title="Schedule this report" alt="CalendarIcon" class="over"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<img src="../../Images/Header/EmailIcon.png" title="Email this report" alt="EmailIcon" class="over"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<img id="container" src="../../Images/Header/PrintIcon.png" title="Print" alt="PrintIcon" class="over"/>
</div>
                <div class="headerMenu"><img src="../../Images/Header/MenuIcon.png" id="MenuIcon" title="Click to open the menu" alt="MenuIcon" class="over"/>
<table class="menuTable" id="menuTableId"  cellspacing="0" cellpadding="0">
<thead>
<tr class="scrollUpArrow">
<th>
</th>
</tr>
</thead>

<tfoot>
<tr class="scrollDownArrow">
<td>
</td>
</tr>
</tfoot>

 <tbody id="contents" class="tablebody" style="overflow:hidden">
    <tr class="trmenuClass" id=favoritestrId>
    <td class="cellBackground">
    <div class="minusSign" id=favoritesMinusSignId>  
    <div class=favIcon id=divFavoritesid>
    <div class="cellName">

    Favorites
    </div>
    </div>
    </div>
    </td>
    </tr>
    <tr class="favtrClass" id="submenufavouritestrId">
    <td class="subMenuCell" id="idFavorites">
    <div class="subMenuCellName">
    1st name
    </div>
    </td>
    </tr>
    <tr class="favtrClass" id="submenufavouritestrId">
    <td class="subMenuCell" id="idFavorites">
    <div class="subMenuCellName">
    2nd name
    </div>
    </td>
    </tr>
    <tr class="favtrClass" id="submenufavouritestrId">
    <td class="subMenuCell" id="idFavorites">
    <div class="subMenuCellName">
    3rd name
    </div>
    </td>
    </tr>
    <tr class="trmenuClass" id=dashboardtrId>
    <td class="cellBackground">
    <div class="minusSign" id=dashboardMinusSignId>  
    <div class=dashboardIcon id=divDashBoardid>
    <div class="cellName">

    Dashboard
    </div>
    </div>
    </div>
    </td>
    </tr>
    <tr class="dashboardtrClass" id="submenudashboardtrId">
    <td class="subMenuCell" id="idDashboard">
    <div class="subMenuCellName">
    Dashboard Item 1
    </div>
    </td>
    </tr>
    <tr class="dashboardtrClass" id="submenudashboardtrId">
    <td class="subMenuCell" id="idDashboard">
    <div class="subMenuCellName">
    Dashboard Item 2
    </div>
    </td>
    </tr>
    <tr class="dashboardtrClass" id="submenudashboardtrId">
    <td class="subMenuCell" id="idDashboard">
    <div class="subMenuCellName">
    Dashboard Item 3
    </div>
    </td>
    </tr>
    <tr class="trmenuClass" id=connecttrId>
    <td class="cellBackground">
    <div class="minusSign" id=connectMinusSignId>  
    <div class=connectIcon id=divConnectid>
    <div class="cellName">

    Connect
    </div>
    </div>
    </div>
    </td>
    </tr>
    <tr class="connecttrClass" id="submenuconnecttrId">
    <td class="subMenuCell" id="idConnect">
    <div class="subMenuCellName">
    Joe Smith
    </div>
    </td>
    </tr>
    <tr class="connecttrClass" id="submenuconnecttrId">
    <td class="subMenuCell" id="idConnect">
    <div class="subMenuCellName">
    Erin Jones
    </div>
    </td>
    </tr>
    <tr class="connecttrClass" id="submenuconnecttrId">
    <td class="subMenuCell" id="idConnect">
    <div class="subMenuCellName">
    Owen Alexander
    </div>
    </td>
    </tr>
    <tr class="trmenuClass" id=hiretrId>
    <td class="cellBackground">
    <div class="minusSign" id=hireMinusSignId>  
    <div class=hireIcon id=divHireid>
    <div class="cellName">

    Hire
    </div>
    </div>
    </div>
    </td>
    </tr>
    <tr class="hiretrClass" id="submenuhiretrId">
    <td class="subMenuCell" id="idHire" >
    <div class="subMenuCellName">
    Clair Brown
    </div>  
    </td>
    </tr>
    <tr class="trmenuClass" id=retaintrId>
    <td class="cellBackground">
    <div class="minusSign" id=retainMinusSignId>  
    <div class=retainIcon id=divRetainid>
    <div class="cellName">

    Retain
    </div>
    </div>
    </div>
    </td>
    </tr>
    <tr class="retaintrClass" id="submenuretaintrId">
    <td class="subMenuCell" id="idRetain">
    <div class="subMenuCellName">
    some good employee name
    </div>
    </td>
    </tr>
    <tr class="trmenuClass" id=activityreportstrId>
    <td class="cellBackground">
    <div class="minusSign" id=activityreportsMinusSignId>  
    <div class=activityIcon id=divActivityReportsid>
    <div class="cellName">

    Activity Reports
    </div>
    </div>
    </div>
    </td>
    </tr>
    <tr class="activityreportstrClass" id="submenuactivityreportstrId">
    <td class="subMenuCell" id="idActivityReports">
    <div class="subMenuCellName">
    Activity report 1
    </div>
    </td>
    </tr>
    <tr class="activityreportstrClass" id="submenuactivityreportstrId">
    <td class="subMenuCell" id="idActivityReports">
    <div class="subMenuCellName">
    Activity report 2
    </div>
    </td>
    </tr>
    <tr class="activityreportstrClass" id="submenuactivityreportstrId">
    <td class="subMenuCell" id="idActivityReports">
    <div class="subMenuCellName">
    Activity report 3
    </div>
    </td>
    </tr>
    <tr class="activityreportstrClass" id="submenuactivityreportstrId">
    <td class="subMenuCell" id="idActivityReports">
    <div class="subMenuCellName">
    Activity report 4
    </div>
    </td>
    </tr>
    <tr class="activityreportstrClass" id="submenuactivityreportstrId">
    <td class="subMenuCell" id="idActivityReports">
    <div class="subMenuCellName">
    Activity report 5
    </div>
    </td>
    </tr>
    <tr class="activityreportstrClass" id="submenuactivityreportstrId">
    <td class="subMenuCell" id="idActivityReports">
    <div class="subMenuCellName">
    Activity report 6
    </div>
    </td>
    </tr>
    <tr class="activityreportstrClass" id="submenuactivityreportstrId">
    <td class="subMenuCell" id="idActivityReports">
    <div class="subMenuCellName">
    Activity report 7
    </div>
    </td>
    </tr>
    <tr class="activityreportstrClass" id="submenuactivityreportstrId">
    <td class="subMenuCell" id="idActivityReports">
    <div class="subMenuCellName">
    Activity report 8
    </div>
    </td>
    </tr>
    <tr class="activityreportstrClass" id="submenuactivityreportstrId">
    <td class="subMenuCell" id="idActivityReports">
    <div class="subMenuCellName">
    Activity report 9
    </div>
    </td>
    </tr>
    <tr class="activityreportstrClass" id="submenuactivityreportstrId">
    <td class="subMenuCell" id="idActivityReports">
    <div class="subMenuCellName">
    Activity report 10
    </div>
    </td>
    </tr>
    <tr class="activityreportstrClass" id="submenuactivityreportstrId">
    <td class="subMenuCell" id="idActivityReports">
    <div class="subMenuCellName">
    Activity report 11
    </div>
    </td>
    </tr>
    <tr class="activityreportstrClass" id="submenuactivityreportstrId">
    <td class="subMenuCell" id="idActivityReports">
    <div class="subMenuCellName">
    Activity report 12
    </div>
    </td>
    </tr>

</tbody>


</table>
</div>
                <div class="headerTitle"><img src="../../Images/Header/TitleArrow.png" alt="Arrow" style="vertical-align:top;"/>
<ul class="segmentControl">
</ul>
</div>
            </div>



        <div class="content">

<h2>Homepage</h2> - <a href="/Dashboard/All">Link to Dashboard/All</a>
        </div>
        <div class="Push"></div>
  </div>  

    <div class="footerWrapper">
        <div class="footer">
            <div class="footerLeft"></div>
            <div class="footerRight"></div>
            <div class="footerRightContent"><a href="/Home/PrivacyPolicy">Privacy Policy</a></div>
            <div class="footerLeftContent">&copy; Copyright 2012 - All Rights Reserved</div>
        </div>
    </div>
</body>
</html>

3 个答案:

答案 0 :(得分:1)

实际上令人尴尬的是,我们能够将问题追踪到浏览器设置。活动脚本已禁用。

工具&gt;互联网选项&gt;安全&GT;单击自定义级别按钮&gt;向下滚动到Scripting&gt;活动脚本

感谢所有发帖的人。我很感激你的时间和努力。

答案 1 :(得分:0)

尝试以下方法:

$(function () {
    $("#container").hover('',function(){ 
        alert("Out"); 
    });
    $("img.over").each(function () {
        var t = $(this),
            src1 = t.attr("src"),
            newSrc = src1.substring(0, src1.lastIndexOf("."));
        t.hover(function () {
            $(this).attr("src", newSrc + "Over." + /[^.]+$/.exec(src1));
        }, function () {
            $(this).attr("src", newSrc + "." + /[^.]+$/.exec(src1));
        });
    });
});

答案 2 :(得分:0)

这里要注意的一件事是你在这些行中完成了两次document.ready

$(document).ready(function () {
$(function () { // this line does the same as $(document).ready(function () {