如何在錨標記中使用 jQuery 新增標題?


若要在 jQuery 中的錨標記中新增標題,請使用 prop() 方法。prop() 方法用於設定所選元素的屬性和值。

您可以嘗試執行以下程式碼來學習如何使用 jQuery 在錨標記中新增標題 −

示例

線上演示

<html>
   <head>
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
      <script>
       $(document).ready(function(){
         $("#button1").click(function(){
            $('.myClass').prop('title', 'This is your new title');
            var myTitle = $('.myClass').prop('title');
            alert(myTitle);
         });
       });
      </script>
   </head>
   <body>
      <div id='div1' class="myclass">
         <a class="myClass" href='#'><img src='https://tutorialspoint.tw/green/images/logo.png' /></a><br>
         <button id="button1">Get Title</button>
      </div>
   </body>
</html>

更新於:2020-02-13

2K+ 瀏覽次數

開始你的 職業生涯

透過完成課程獲得認證

開始吧
廣告
© . All rights reserved.