我有一个下拉菜单,当您在对话框内的网格中单击一个图标(黑色的小过滤器实际上是一个链接)时,它会打开。如果我从 target.position() 获得坐标,它在 Chrome 中的位置是完美的。
这是在 Chrome 中使用 target.position() 的屏幕截图:
scope.showFilterMenu = function ($event, id) {
var modal = $('div[kendo-window]');
var target = $($event.currentTarget);
var offset = target.position(); // THIS WORKS FOR CHROME BUT NOT IE
var offset = target.offset(); // THIS WORKS FOR IE BUT NOT CHROME
var top = offset.top;
var left = offset.left + 25; // 25 is extra buffer
modal.append(filterMenu);
var filterMenu = $('ul[sgid=' + id + ']'); // the dropdown menu is a ul list
filterMenu.css({
'width': 50 + 'px',
'top': dd_top + 'px',
'position': 'fixed', // must be fixed so that it follows the window contract and expand
'left': left // align LHS with filter icon
});
}
但是在 IE 中使用 target.position() 会完全关闭它,我必须改用 target.offset() 。有谁知道如何找到适用于这两种浏览器的解决方案?
最佳答案
为什么不做一个简单的if 条件
?像 if(IE) {X} else {Y}
var IE = (document.all) ? true : false;
编辑:
另外你也可以检查这个:
var ie_browser = jQuery.browser.msie;
好吧,忽略这个。它在 jQuery 1.9 中被删除。
也许这有帮助: 包含 IE 11 更新。 Check if user is using IE with jQuery
关于javascript - 如何在 IE 和 Chrome/Firefox 中放置一个 css 下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27294460/