我有一个 div,当单击表格单元格时,我想直接显示在表格单元格下方。到目前为止,这是我的代码示例...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript">
function toggleDownloadSelectionDialog(divToggle,divId,event){
pos_x = event.offsetX?(event.offsetX):event.pageX-document.getElementById(divToggle).offsetLeft;
pos_y = event.offsetY?(event.offsetY):event.pageY-document.getElementById(divToggle).offsetTop;
alert(pos_y+" "+pos_x+" "+divId);
document.getElementById(divId).style.top = pos_y;
document.getElementById(divId).style.left = pos_x;
document.getElementById(divId).style.display = 'block';
}
</script>
</head>
<body>
<div class="div_downloadDialog" id="div_hidden1" style="display: none; top: 0; left: 0; position: absolute;">This div is hidden</div>
<table class="Oligo_Diversity">
<tr>
<td>blah</td><td>blah</td><td>blah</td>
</tr>
<tr>
<td><div id="div_toggle1" onclick="toggleDownloadSelectionDialog('div_toggle1','div_hidden1',event);">click here for download dialog</div></td>
<td>blah</td>
<td>blah</td>
</tr>
</table>
</body>
</html>
我希望隐藏的下载 div 直接显示在单击它的表格单元格下方。我的 javascript 似乎获得了位置,但我无法将此信息传递给 div。删除 DOCTYPE 将使这项工作有效,但对于我正在处理的项目,我需要一个 doctype。有什么建议么?