【发布时间】:2020-08-05 14:32:30
【问题描述】:
我正在尝试在鼠标悬停时添加一个弹出窗口。每行都有多个 td,并且弹出窗口应该只对第一个有效。只要 mouseout 在同一列中,此方法就有效。也就是说,如果我上下移动鼠标,弹出窗口会按预期出现和消失。但是,如果我将鼠标水平移动到下一个 td,弹出窗口不会消失。我为此创建了一个jsfiddle,但弹出窗口不起作用。控制台说没有定义 javascript 函数,但它在这里工作正常,所以我在 jsfiddle 设置中一定有问题。这是我正在使用的代码。正在使用 Td,因为这是给我的代码。无论鼠标如何移动,任何人都可以看到隐藏弹出窗口需要什么?
已编辑以解决问题。
<style>
#pop-description{
display : none;
position : absolute;
z-index : 99999;
left : 0px;
padding : 10px;
background : #3AB9AE;
border : 1px solid #9a9a9a;
margin : 0px;
}
</style>
<script>
$(document).ready(function(){
function ShowDescription(id) {
var position = $('.class-desc-'+id).position();
var desc = $('#desc-'+id).val();
$('#pop-description').css('top', position.top);
$('#pop-description').text(desc);
//$('#pop-description').toggle();
$('.class-desc-'+id).mouseenter(function() {
$('#pop-description').css('display', 'block');
}).mouseleave(function() {
$('#pop-description').css('display', 'none');
});
}
});
</script>
<div style="display:relative;"><div id="pop-description" style="display:none;"></div></div>
<table>
<tr>
<td class="class-desc-0" onmouseOver="ShowDescription('0');">title</td>
<td>Address</td>
<td>State</td>
<input type="hidden" name="desc-0" value="first test" id="desc-0">
</tr>
<tr>
<td class="class-desc-1" onmouseOver="ShowDescription('1');">title</td>
<td>Address</td>
<td>State</td>
<input type="hidden" name="desc-1" value="second test" id="desc-1">
</tr>
<tr>
<td class="class-desc-2" onmouseOver="ShowDescription('2');">title</td>
<td>Address</td>
<td>State</td>
<input type="hidden" name="desc-2" value="third test" id="desc-2">
</tr>
</table>
【问题讨论】:
标签: javascript jquery popup onmouseout