简体   繁体   English

为什么我的 Jquery 工具提示不起作用?

[英]Why is my Jquery Tooltip not working?

I am not getting a tooltip to work and I think the problem is with my selector.我没有得到工具提示,我认为问题出在我的选择器上。 I had selected a plugin that is located here: http://flowplayer.org/tools/tooltip/index.html It says that you can use the title attribute of an element as the selector.我选择了一个位于此处的插件: http://flowplayer.org/tools/tooltip/index.html它说您可以使用元素的标题属性作为选择器。 I am wanting to select menu items and attach a tooltip to each one (to describe the menu links).我想要 select 菜单项并为每个菜单项附加一个工具提示(以描述菜单链接)。 It seemed that the easiest way to do this is to use the title attribute.似乎最简单的方法是使用 title 属性。 I only need to fit about 10 or less words in each tooltip.我只需要在每个工具提示中放置大约 10 个或更少的单词。 Before describing what could be the problem, let me also mention a couple things.在描述可能是什么问题之前,让我还提到几件事。

I have on the page a JQuery accordion too, from the jqueryui.com site.我在页面上也有一个 JQuery 手风琴,来自 jqueryui.com 站点。 That link to the jqueryui is placed after the call to the jquery tools from http://flowplayer.org/tools/tooltip/index.html .到 jqueryui 的链接是在从http://flowplayer.org/tools/tooltip/index.html调用 jquery 工具之后放置的。 I thought this was the jquery ui at first but jqueryui doesn't have a tooltip - though they have a dialog box that is similar but I don't need the header, just room for a few words.起初我以为这是 jquery ui,但 jqueryui 没有工具提示 - 尽管它们有一个类似的对话框,但我不需要 header,只需要几句话的空间。

So, let's see where I could have went wrong.所以,让我们看看我哪里可能出错了。 A) The call to the jquery tools comes before the call to the jqueryui. A) 在调用 jqueryui 之前调用 jquery 工具。 When that was reversed, my accordion didn't work.反过来,我的手风琴就坏了。

B) The plugin documentation says that there is a class.tooltip which is available by default and the code also let me set the class for the tooltip to tooltip. B)插件文档说有一个 class.tooltip 默认情况下可用,代码还让我将工具提示的 class 设置为工具提示。 It is definitely not getting any of the styling that I setup for the tooltip.它绝对没有得到我为工具提示设置的任何样式。 I'm not sure how to confirm that this tooltip class exists because it only shows up when the tooltip appears.我不确定如何确认此工具提示 class 存在,因为它仅在工具提示出现时显示。

C) My selector. C) 我的选择器。 At first I tried a CSS Descendant selector, just like I would in CSS.起初我尝试了 CSS 后代选择器,就像我在 CSS 中一样。 I even added a containing div with id of tooltip.我什至添加了一个包含工具提示 id 的 div。

1)First selector: $('#tooltip a[title]), to get the a tags that have a title attribute. 1)第一个选择器:$('#tooltip a[title]),获取具有title属性的a标签。 That was described in the documentation, though to me it seems like you would want to "trigger" on the anchor tag, not it's title attribute 2) Second attempt with descendant selectors $(".art-hmenu a.tt[title]") - I have inside the tag that has a class of art-hmenu an anchor tag with class tt and I want the title attribute.这在文档中有所描述,但在我看来,您似乎想要在锚标记上“触发”,而不是它的标题属性 2) 第二次尝试使用后代选择器 $(".art-hmenu a.tt[title]" ) - 我在标签里面有一个 class 的 art-hmenu 一个锚标签 class tt 我想要标题属性。 - didn't work. - 没用。 3) lastly, I tried using ("#tooltip").find('a[title]') - thinking this would find the anchor tag with title attribute. 3) 最后,我尝试使用 ("#tooltip").find('a[title]') - 认为这会找到带有 title 属性的锚标记。 The documentation page says that this code will take advantage of the element's title attribute: $("img[title]").tooltip();文档页面说此代码将利用元素的标题属性: $("img[title]").tooltip(); That might put a tooltip on every img tag, wouldn't it?这可能会在每个 img 标签上放置一个工具提示,不是吗? My first example above is similar in using ("#tooltip a:[title]") which doesn't work.我上面的第一个示例与使用 ("#tooltip a:[title]") 类似,但它不起作用。 Maybe the title shouldn't be on the anchor tag but instead on the li tag.也许标题不应该在锚标签上,而是在 li 标签上。 I could use some help figuring this out - wherever the problem might lay, which I think is how I am making my selection.我可以使用一些帮助来解决这个问题 - 无论问题出在哪里,我认为这就是我做出选择的方式。 Thanks, Bruce谢谢,布鲁斯

your looking for an attribute so use the $('#tooltip a').attr("title") instead.您正在寻找一个属性,所以请改用$('#tooltip a').attr("title")

It sounds like you are over-complicating this.听起来你过于复杂了。 Give the link, phrase, input, button the class of "trigger" and a title.给出链接、短语、输入、按钮“触发器”的 class 和标题。 Tools will handle everything else.工具将处理其他所有事情。 You can style the tooltip with a.tooltip class.您可以使用 a.tooltip class 设置工具提示的样式。 You position the tooltip with the offset and position settings.你 position 带有偏移和 position 设置的工具提示。 If you want to get crazy with styling you can layout: or open the plugin source code and wrap html around the Append(title).如果您想对样式感到疯狂,您可以布局:或打开插件源代码并将 html 包裹在 Append(title) 周围。

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

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