我正在使用document.elementFromPoint获取所选元素以进行拖动。但它返回null。当我调试相同,然后重新运行相同的代码,对象返回。document.elementFromPoint在IE上返回null
以下是代码:
function GetZoneFromPoint(x, y, prtDrag, elemIBeam,evnt) {
if (x == null || y == null || prtDrag == null || elemIBeam == null)
alert("Null in GetZone");
var prtDragZIndexOld = prtDrag.style.zIndex;
var elemIBeamZIndexOld = elemIBeam.style.zIndex;
prtDrag.style.zIndex = -1;
elemIBeam.style.zIndex = -1;
var zone;
zone = document.elementFromPoint(x, y);
prtDrag.style.zIndex = prtDragZIndexOld;
elemIBeam.style.zIndex = elemIBeamZIndexOld;
if (zone == null) {
zone = document.elementFromPoint(x, y);
if (zone == null) {
debugger;
zone = event.rangeParent;
}
}
if (zone == null) {
alert('null');
return null;
}
if (x < 0 || x > document.body.clientWidth ||
y < 0 || y > document.body.clientHeight) {
zone = null;
}
else if ((zone.className == 'LayoutWellElement') ||
(zone.className == 'LayoutMainElement') ||
(zone.className == 'ElementFrame')) {
while ((!FIsZone(zone)) && (zone.tagName != 'BODY')) {
zone = zone.parentElement;
}
}
if (!FIsZone(zone)) {
zone = null;
}
return zone;
}