當我點擊文本框內部的工具提示顯示,當我使用下面的JavaScript代碼和CSS退出文本框工具提示消失。問題在於頁面的滾動。工具提示的位置變化等於滾動值。如何修復HTML中文本框相對於工具提示的位置?如何修復相對於文本框在HTML工具提示的位置?
<style type="text/css">
.tooltip {
visibility: hidden;
position: fixed;
width: 450px;
top: 0;
left: 0;
z-index: 2;
color: red;
background-color: #ffffe6;
font-family: 'B Yekan';
font-size: 20px;
text-align: center;
padding: 1px;
border: solid 1px;
border-radius: 5px;
overflow:auto;
}
</style>
<script type="text/javascript">
function tooltip_show(tooltipId, inputId) {
var inputField = document.getElementById(inputId);
var rectObject = inputField.getBoundingClientRect();
var top = rectObject.top, left = rectObject.left;
var it = document.getElementById(tooltipId);
it.style.left = (left - it.offsetWidth/2 + inputField.offsetWidth/2) + 'px';
it.style.top = (top + inputField.offsetHeight + 5) + 'px';
var a = inputField.scrollTop;
it.style.visibility = 'visible';
}
function tooltip_hide(tooltipId) {
var it = document.getElementById(tooltipId);
it.style.visibility = 'hidden';
}
</script>
共享html代碼,請 – Ehsan