在 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 年 6 月 25 日

975 次瀏覽

開啟您的 職業

完成課程並獲得認證

入門
廣告
© . All rights reserved.