不使用z-index时,将鼠标悬停在该元素上时无法获得div值。
<div id="main" style="width:150px;height:150px;position:absolute;background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255);"><span id="test" onmouseover="return test();">helo</span></div>
<textarea style="width:150px;height:150px;position:relative;background:none;"></textarea>
<script>
function test(){
alert('hi');
}
</script>
将鼠标悬停在文本上时如何获取测试id值(不给textarea提供z-index)?
看看这是否就是您想要发生的事情:
var s_val = document.getElementById("span").innerHTML;
var tArea = document.getElementById("test");
tArea.addEventListener("mouseover", function test(){
alert(s_val);
});
#main {
width:150px;
height:150px;
position:absolute;
background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255);
}
#test {
width:150px;
height:150px;
position:relative;
background:none;
}
<div id="main">
<span id="span">helo</span>
</div>
<textarea id="test"></textarea>
只需获取<span>
usinginnerHTML
事件的值(存储在var中以获取更好的视图),然后在上调用它即可alert()
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句