JQuery 工具提示不显示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15534061/
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
JQuery tooltip not displaying
提问by Ryan Taylor
I'm trying to set a tooltip for some listed elements using jquery ui but I can't get the tooltips to show. I'm trying to apply a tooltip to all items using the tooltip class. Please check my code for problems...
我正在尝试使用 jquery ui 为某些列出的元素设置工具提示,但无法显示工具提示。我正在尝试使用工具提示类将工具提示应用于所有项目。请检查我的代码是否有问题...
HTML
HTML
<li>
<label>
<input id="someid" type="radio" name="name" />
<strong><span>text</span></strong></label>
<a href="#" class="tooltip" title="some text"></a>
<h4>text</h4>
</li>
JS
JS
function showTooltip() {
$("#tooltip").each(function()
{
$(this).tooltip();
};
};
Thanks :)
谢谢 :)
采纳答案by TiagoBrenck
Your function must have a class selector: $(".class")... not $("#id")
你的函数必须有一个类选择器: $(".class")... 而不是 $("#id")
$(function(){
showTooltip();
function showTooltip() {
$(".tooltip").each(function() {
$(this).tooltip();
});
}
});
回答by Kickass
For anyone else struggling with tooltip not working.
对于其他任何因工具提示不起作用而苦苦挣扎的人。
I have found a number of issues with jquery-ui as of late, however it seems they did not handle null input of the default item content.
最近我发现 jquery-ui 存在许多问题,但是它们似乎没有处理默认项目内容的空输入。
Thus by default it is 'title' so if you did not enter a title attribute to the element you want to make the tooltip object it will fail even if you specify the content like so:
因此,默认情况下它是 'title' 所以如果您没有为要制作工具提示对象的元素输入 title 属性,即使您像这样指定内容,它也会失败:
$("#element").tooltip({content:"test"});
It's pretty weak not to handle null(or undefined) values in my opinion but that's how it is.
在我看来,不处理空(或未定义)值是很弱的,但事实就是如此。
I handled it by adding a title attribute like so to the element:
我通过向元素添加这样的标题属性来处理它:
title=''
I guess you could specify a items
in the tooltip constructer like so:
我想您可以items
在工具提示构造函数中指定 a ,如下所示:
$("#selector").tooltip({items:'other-title', content: 'test'});
But then you would still need to add the new attribute to the element like so:
但是你仍然需要像这样向元素添加新属性:
other-title=''
PS: using JQuery-UI 1.11.4
PS:使用 JQuery-UI 1.11.4
回答by Joe Pigott
回答by neodonator
when I used $(document).tooltip(); , It made tooltip for every element, to get tooltip for specific I used,
当我使用 $(document).tooltip(); , 它为每个元素制作了工具提示,以获取我使用的特定工具提示,
$(function () {
$(document).tooltip({
track: true,
items: ".tooltip",
content: function () {
return $(this).attr("title");
}
});
});
回答by HoldOffHunger
Like others are saying, all you should need is the following:
就像其他人所说的那样,您只需要以下内容:
$(document).tooltip();
But there are exceptions where this alone will just not work. Specific cases where this will not work:
但也有例外,仅此一项是行不通的。这不起作用的具体情况:
option
elements within aselect
block. (tooltip displays underneath the select option)disabled="true"
elements will continue to display tooltips in non-jQuery-UI format until re-enabled.
option
select
块内的元素。(工具提示显示在选择选项下方)disabled="true"
元素将继续以非 jQuery-UI 格式显示工具提示,直到重新启用。
Besides reprogramming jQuery-UI, I have found no real solution to these problems.
除了重新编程 jQuery-UI 之外,我还没有找到解决这些问题的真正方法。