如何使用 jQuery 滑鼠懸停時給超連結加下劃線?


要使用 jQuery 在滑鼠懸停時給超連結加下劃線,請使用 jQuery css() 屬性。使用 color text-decoration 屬性。

範例

您可以嘗試執行以下程式碼來了解如何使超連結在滑鼠懸停時加下劃線

即時演示

<html>

   <head>
      <title>jQuery Hyperlink Decoration</title>
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
       
      <script>
         $(document).ready(function() {

            $('a').hover(
               
               function () {
                  $(this).css({"text-decoration":"underline"});
               });
               
         });
      </script>
      <style>
      a {
           text-decoration: none;
         }
     </style>
   </head>
   
   <body>
      <a href="#">Demo text</a>
       
   </body>
   
</html>

更新於: 11-Dec-2019

527 次瀏覽

開啟您的職業生涯

完成課程即可獲得認證

開始學習
廣告
© . All rights reserved.