简体   繁体   English

如何在Bootstrap中检索按钮的工具提示文本?

[英]How to retrieve tool-tip text of a button in Bootstrap?

I have the following HTML snippet below. 我下面有以下HTML代码段。 I want to retrieve the tool tip title (78) of the button and use it in another function. 我想检索按钮的工具提示标题(78)并将其用于其他功能。

<span class="btn btn-warning btn-sm" data-toggle="tooltip" data-placement="top" title="78" onclick="showToolTipTitle(event);">10:15 AM</span>   

I tried using the following javascript codes to retrieve the tool-tip title but it still doesn't work: 我尝试使用以下javascript代码检索工具提示标题,但仍然无法正常工作:

function showToolTipTitle(event)
{   
    var title = $(event.target).attr("tooltip").text;
    alert(title);
}

function showToolTipTitle(event)
{   
    var title = $(event.target).attr("title");
    alert(title);
}
<script>
$(document).ready(function(){
    $("button").click(function(){
        var new_title = $(this).attr("title");
        alert(new_title);
    });
});
</script>

<button data-toggle="tooltip" data-placement="top" title="34">Display Tooltip</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM