实现的效果是:
点击div1时,text1中显示div1的id
点击div2时 ,text1中就显示div2的id
问题是:
ie下 单独运行a页面是好好的,运行b页面时,alert(obj) 一下空值,一下正常得到div,请问怎么搞定??a.html 页码a<html>
<head>
<script>
function dealDown(e){
document.getElementById('div3').style.display = 'none';//将div3隐藏不需要获得div3,div3覆盖在上面的div作为事件触发者
var obj = document.elementFromPoint(e.clientX, e.clientY);
document.getElementById('div3').style.display = 'block';
alert(obj)
document.getElementById('text1').value = obj.id;
}
</script>
</head>
<body>
<div id="div1" style="width:100px; height:100px; background-color:#CCCCCC"></div>
<div id="div2" style="width:100px; height:100px; background-color:#669966"></div>
<div onmousedown="dealDown(event)" style="position:absolute; top:0px; left:0px; width:200px; height:500px;" id="div3"></div>
<input type="text" id="text1" />
</div>
</body>
</html>
------------------------------------------b.html 页面b
<html>
<body>
<div style=" height:600px; width:600px;">
<iframe src="a.html" style="width:100%; height:100%;">
</iframe>
</div>
</body>
</html>
点击div1时,text1中显示div1的id
点击div2时 ,text1中就显示div2的id
问题是:
ie下 单独运行a页面是好好的,运行b页面时,alert(obj) 一下空值,一下正常得到div,请问怎么搞定??a.html 页码a<html>
<head>
<script>
function dealDown(e){
document.getElementById('div3').style.display = 'none';//将div3隐藏不需要获得div3,div3覆盖在上面的div作为事件触发者
var obj = document.elementFromPoint(e.clientX, e.clientY);
document.getElementById('div3').style.display = 'block';
alert(obj)
document.getElementById('text1').value = obj.id;
}
</script>
</head>
<body>
<div id="div1" style="width:100px; height:100px; background-color:#CCCCCC"></div>
<div id="div2" style="width:100px; height:100px; background-color:#669966"></div>
<div onmousedown="dealDown(event)" style="position:absolute; top:0px; left:0px; width:200px; height:500px;" id="div3"></div>
<input type="text" id="text1" />
</div>
</body>
</html>
------------------------------------------b.html 页面b
<html>
<body>
<div style=" height:600px; width:600px;">
<iframe src="a.html" style="width:100%; height:100%;">
</iframe>
</div>
</body>
</html>
记得是frame[0].****
这样的调用方式
我试一下
但是在IE8下就出现楼主说的问题了
一下是null 一下是div...
function dealDown(e) {
document.getElementById('div3').style.display = 'none';
setTimeout((function(x, y) {
return function() {
var obj = document.elementFromPoint(x, y);
document.getElementById('div3').style.display = 'block';
document.getElementById('text1').value = obj.id;
}
})(e.clientX, e.clientY), 100);
}