獲取移動瀏覽器中 HTML 中的工具提示


當您單擊具有標題屬性的元素時,將附加一個包含標題文字的子元素。我們來看一個示例 −

對於 HTML −

<p>
   The <span class="demo" title="this is underscore">underlined</span> character.
</p>

jQuery −

$("span[title]").click(function () {
   var $title = $(this).find(".title");
   if (!$title.length) {
      $(this).append('<span class="title">' + $(this).attr("title") + '</span>');
   } else {
      $title.remove();
   }
});

以下是 CSS

.demo {
   border-bottom: 2px dotted;
   position: relative;
}
.demo .title {
   position: absolute;
   top: 15px;
   background: gray;
   padding: 5px;
   left: 0;
   white-space: nowrap;
}

更新於: 2020-06-25

978 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.