twitter-bootstrap Bootstrap 工具提示不适用于输入字段

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16079884/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 16:56:14  来源:igfitidea点击:

Bootstrap Tooltip not working on input field

twitter-bootstraptooltip

提问by Rajeev

I,m using tooltip in my Rails app but it not working on input field as my code is:

我在我的 Rails 应用程序中使用了工具提示,但它在输入字段上不起作用,因为我的代码是:

  %input#main-search{:name => "query", :placeholder => "search all 
    items", :rel => "tooltip", :title => "Search All Items", :type => "text"}
  :javascript
    $(document).ready(function(){
      $('input[title]').tooltip({placement:'bottom'});
    });

I also use:

我也用:

$('#main-search').tooltip({'trigger':'focus'});

Its not work for input field but for label it works fine. how can I inable tooltip for input field?

它不适用于输入字段,但对于标签它工作正常。如何禁用输入字段的工具提示?

回答by Miljan Puzovi?

Here is valid HTML markup for tooltip:

这是工具提示的有效 HTML 标记:

<input data-toggle="tooltip" title="tooltip on second input!" type="text" placeholder="Focus me!" name="secondname"/>

And here is jQuery with right placement for tooltip and trigger on focus:

这是 jQuery 的工具提示和触发焦点的正确位置:

$('input[type=text][name=secondname]').tooltip({ /*or use any other selector, class, ID*/
    placement: "right",
    trigger: "focus"
});

Always look at official docs.

始终查看官方文档

And here is working demo: http://jsfiddle.net/N9vN8/69/

这是工作演示:http: //jsfiddle.net/N9vN8/69/

回答by Pathros

It is simpler to activate it to all inputs or glyphicons where you want to use a tooltip by just typing the following script:

只需键入以下脚本,就可以更简单地将其激活到您想要使用工具提示的所有输入或字形:

<script type="text/javascript">
$(function () {
                $('[data-toggle="tooltip"]').tooltip()
            });
</script>

Inside an input:

在输入中:

<input data-toggle="tooltip" data-placement="left" title="Your awesome tip!" type='text' class="form-control" name="name"  placeholder="placeholder" maxlength="10"/>

Inside a glyphicon:

在字形内:

<span class="glyphicon glyphicon-calendar" data-toggle="tooltip" data-placement="right" title="Open calendar"></span>

This way you don't need to worry about any IDs when using tooltips in several inputs in the same form.

这样,在同一表单的多个输入中使用工具提示时,您无需担心任何 ID。

Source: docs.

来源:文档