鼠標懸停在一個標簽上時,顯示一段文字


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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM