JQuery 和 IE8、兼容模式和 IE7 模拟

标签 jquery internet-explorer-8 ie8-compatibility-mode

我正在使用在 IE8 中开发和测试的 JQuery 解决方案。

我有一个用户,在“工具”>“兼容性 View 设置”下具有“在兼容性 View 中显示所有网站”。并且部分 JQuery 失败。

$(document).ready(function() {

    // creating named variables to represent the throbber objects to make life easier later.
    var moSearchThrobber = $("#imgSearchThrobber");
    var moFilterThrobber = $("#imgFilterThrobber");

    //lets hide the search and filter dialogs.
    $("div[id*=pnlSearch_Dialog]").hide();
    $("div[id*=pnlFilter_Dialog]").hide();

    // when I change the value of my drop downs in search and in filter, set the hidden field value.
    $("select[name=ddlValue]").change(function() {
        $(this).siblings("input:hidden").val($(this).val());
    });
    // If the user clicks on the Search link button.
    $("a[id*=lnkSearch").click(function() {

        // while we are at it turn on the search throbber
        moSearchThrobber.css('visibility', 'visible');

        // find the search grid and get/each through all the rows.
        $("table[id*=grdSearch]").find("tr").each(function() {

隐藏功能有效...但单击方法无法触发...

我一直在考虑尝试将其强制进入 IE8 并通过元标记关闭兼容模式...但这对我来说感觉很脏。此时是否还有其他选项可以使 jquery 在 IE8 的所有 3 个“版本”中同样工作?

最佳答案

由于我的评论似乎解决了您的问题,因此我正在对其进行调整以适应答案。

您的 lnkSearch 选择器中缺少结束方括号 (])。我本以为这会在 IE8 和 IE9 中中断,但显然 document.querySelectorAll() 接受它。然而,IE7使用sizzle因为它不支持 document.querySelectorAll()。看来 sizzle 不喜欢格式错误的属性选择器。

这是一个test page with malformed attribute selectors 。在 IE9、IE8、IE7 模式之间切换,可以看到在 IE9 和 IE8 中可以正常工作,但在 IE7 中却无法正常工作。

这是test page with corrected attribute selectors 。请注意,它适用于所有版本。

关于JQuery 和 IE8、兼容模式和 IE7 模拟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9119088/

相关文章:

Javascript - jQuery 验证插件规则方法不起作用

javascript - 将事件添加到完整日历并通过servlet回调将它们存储在mysql上

css - 自定义标签在 ie8 中不起作用

asp.net - SQL Server SSRS 2012 网页中的 HTTP 元标记

internet-explorer - 以编程方式从 IE 'internet explorer' 中删除兼容性 View 按钮?

jQuery 代码在 Safari 中工作,但在 Firefox 中不工作

javascript - 单击事件的 jquery 代码不起作用

css - 使用百分比和最大宽度将图像裁剪成正方形

internet-explorer - Raphaeljs 在 IE 中将所有文本呈现为斜体

html - IE frameBorder替代方案