twitter-bootstrap Glyphicon 上的 Bootstrap 3 工具提示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19688974/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bootstrap 3 Tooltip over Glyphicon
提问by user2449026
Not sure if this even possible, I am trying to invoke a tooltip over a glyphicon inside an input group, my code (which does not work) is;
不确定这是否可能,我试图在输入组内的字形上调用工具提示,我的代码(不起作用)是;
<div class="input-group">
<input type="text" class="form-control" name="security" id="security"><span class="input-group-addon"><span class="glyphicon glyphicon-info-sign" data-toggle="tooltip" data-container: 'body' title="" data-original-title="Security Code"></span></span>
</div>
I'm using Bootstrap 3, and the latest version of jQuery.
我正在使用 Bootstrap 3 和最新版本的 jQuery。
回答by Dennis
You can get a simple tooltip over the glyphicon using the title attribute (which is blank in your example).
您可以使用 title 属性(在您的示例中为空白)在字形上获得一个简单的工具提示。
title="info"
Working code
工作代码
// add this in your js
// all the glyphicons having the class "my-tooltip" will show a tooltip if "title" attribute is present
$(".my-tooltip").tooltip();
<span class='glyphicon glyphicon-info-sign my-tooltip' title="here goes the tooltip text"></span>
回答by Android334
Using @MadHyman's answer I rewrote your code and tested on JSFiddle.
使用@MadHyman 的回答,我重写了您的代码并在 JSFiddle 上进行了测试。
HTML:
HTML:
<div class="input-group" style='margin-top: 100px;'>
<input type="text" class="form-control" name="security" id="security">
<span class="input-group-addon">
<a class='my-tool-tip' data-toggle="tooltip" data-placement="left" title="Tooltip here">
<!-- The class CANNOT be tooltip... -->
<i class='glyphicon glyphicon-info-sign'></i>
</a>
</span>
</input>
</div>
JS:
JS:
$("a.my-tool-tip").tooltip();
Hope this helps,
希望这可以帮助,
-Andrew
-安德鲁
回答by Web_Developer
<span class="glyphicon glyphicon-info-sign icon_info" title="info"></span>
Then add javascript code to initialize tooltip like below:
然后添加 javascript 代码来初始化工具提示,如下所示:
$(".icon_info").tooltip();
回答by Hymanfrosch
A Bootstrap newbie here...
这里是一个 Bootstrap 新手......
To use the Tooltip plugin with the glyph-icon, I've found success wrapping the glyph-icon span tag with an anchor tag having no href:
要使用带有字形图标的工具提示插件,我发现使用没有 href 的锚标记包装字形图标跨度标签是成功的:
<a data-toggle="tooltip" class="tooltipLink" data-original-title="Tooltip text goes here">
<span class="glyphicon glyphicon-info-sign"></span>
</a>
Also, be sure to initialize the tooltips for the links with tooltips:
此外,请务必使用工具提示初始化链接的工具提示:
$("a.tooltipLink").tooltip();
I tested this with Bootstrap 3.03, jQuery 1.10.2 + Firefox 26, Chrome 32.0.1700, and IE 11.0.9600. So far, no hiccups.
我使用 Bootstrap 3.03、jQuery 1.10.2 + Firefox 26、Chrome 32.0.1700 和 IE 11.0.9600 对此进行了测试。到目前为止,没有打嗝。
回答by Hamza Khanzada
Using Bootstrap's Popover makes it a bit nice, Here is the documentation, and sample code snippet
使用 Bootstrap 的 Popover 使它有点好,这是 文档和示例代码片段
$(function () {
$('.fa').popover({trigger: "hover"});
})
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Information Popover snippet">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Information Popover snippet</title>
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
<span><i data-content="Simple Clean way to show more detailed information about anything" class="fa fa-question-circle"></i></span>
</body>
</html>

