[在线]如何让pop窗口精确显示在一个文本框上?

drifters 2004-10-13 06:17:53
文本框在一个iframe中,如何让pop窗口精确显示在一个文本框上?

代码如下
a.htm
=====================================================
<table width="600" border="1">
<tr >
<td width="180">占位</td>
<td height="200" ><iframe name="test" id="test" scrolling="no" noresize src="b.htm" width=100% height=100% frameborder=0></iframe></td>
</tr>
</table>
=====================================================

b.htm
=====================================================
<script>
oPopup = window.createPopup();
function createPop(obj){
var oPopBody = oPopup.document.body
oPopBody.style.backgroundColor = "lightyellow";
oPopBody.style.border = "solid black 1px";
oPopBody.innerHTML = 'test';
//下面代码在iframe中不能精确定位 请忙帮 看看
oPopup.show(window.screenTop, window.screenLeft,300, 200);
}
</script>
<p>占位</p>
<p><input name="b" type="text" id="b" onClick="test(this)"></p>
=====================================================



多谢大家了
...全文
140 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
csdntzg 2004-10-14
  • 打赏
  • 举报
回复
恭喜楼主了,也学习一下
drifters 2004-10-14
  • 打赏
  • 举报
回复
呵呵,放分
Holliet 2004-10-14
  • 打赏
  • 举报
回复
接分学习ing!
blestcc 2004-10-14
  • 打赏
  • 举报
回复
学习楼主的代码去了
yiyioo 2004-10-14
  • 打赏
  • 举报
回复
哈哈
学习加接分喽!~!

micker 2004-10-13
  • 打赏
  • 举报
回复
恭喜楼主了,接分!
cybernaute 2004-10-13
  • 打赏
  • 举报
回复
接分
风斧 2004-10-13
  • 打赏
  • 举报
回复
恭喜,楼主只好散分了。赫赫
drifters 2004-10-13
  • 打赏
  • 举报
回复
找到答案
=============================================
function getAbsPosition(obj)
{
var abs={x:0,y:0}
while(obj!=document.body){
abs.x+=obj.offsetLeft;
abs.y+=obj.offsetTop;
obj=obj.offsetParent;
}
return abs;
}

function test(obj){
x=(window.screenLeft+document.body.clientLeft+getAbsPosition(obj).x-document.body.scrollLeft);
y=(window.screenTop+document.body.clientTop+getAbsPosition(obj).y-document.body.scrollTop);
}
=============================================
drifters 2004-10-13
  • 打赏
  • 举报
回复
刚才有一点错误
b.htm中 input应为如下
<p><input name="b" type="text" id="b" onClick="createPop(this)"></p>

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧