JQuery和IE8,兼容模式和IE7仿真

时间:2012-02-02 20:01:02

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

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

我有一个用户,有"在兼容性视图中显示所有网站"在工具>下兼容性视图设置。并且部分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在所有3"版本中运行相同" IE8?

2 个答案:

答案 0 :(得分:4)

由于我的评论似乎解决了您的问题,我正在调整它以回答。

您在]选择器中缺少结束方括号(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。请注意,它适用于所有版本。

答案 1 :(得分:2)

我使用元标记,HTML 5 Boilerplate和其他信誉良好的来源也是如此。但你是对的,IE是一个肮脏的生意。

编辑:

根据Microsoft,IE = edge应始终为您提供最新的渲染引擎。一个例外是intranet pages,需要明确使用IE = 9来避免兼容模式。