我有一个下拉列表,当你点击对话框内网格中的图标(小的黑色滤镜,实际上是一个链接)时,它就会打开。如果我从target.position()获得坐标,它在Chrome中的位置非常好。
这是使用target.position()在Chrome中的屏幕截图:
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()来代替。有谁知道我怎样才能找到两种浏览器的解决方案?

发布于 2014-12-04 20:53:21
你为什么不做一个简单的if condition呢?像if(IE) {X} else {Y}一样
var IE = (document.all) ? true : false;编辑:
此外,您还可以检查以下内容:
var ie_browser = jQuery.browser.msie;好吧,忽略这个。它在jQuery 1.9中被删除了。
也许这会有所帮助:其中包含了IE11更新。Check if user is using IE with jQuery
https://stackoverflow.com/questions/27294460
复制相似问题