当您单击具有标题属性的元素时,将添加带有标题文本的子元素。让我们看一个例子-
对于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;
}