我正在使用在 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/