鼠标悬停在一个标签上时,显示一段文字

1.使用title属性

<div title="显示文字">
  <p>显示</p>
</div>

2.使用监听鼠标事件onmouseover

<table border="1">
 <tr>
  <td onmouseover="overShow()" onmouseout="outHide()">文字内容2</td>
 </tr>
</table>
<div id="showDiv" style="position: absolute; background-color: white; border: 1px solid black;"></div>
<script>
 function overShow() {
  var showDiv = document.getElementById('showDiv');
  showDiv.style.left = event.clientX;
  showDiv.style.top = event.clientY;
  showDiv.style.display = 'block';
  showDiv.innerHTML = '鼠标停留显示内容2';
 }
 
 function outHide() {
  var showDiv = document.getElementById('showDiv');
  showDiv.style.display = 'none';
  showDiv.innerHTML = '';
 }
</script>
当你的才华还撑不起你的野心时
那你就应该静下心来学习
当你的能力还驾驭不了你的目标时
那就应该沉下心来历练
原文地址:https://www.cnblogs.com/yang-xiansen/p/10282145.html