简体   繁体   English

动态工具提示的Javarscript问题

[英]Javarscript issues with dynamic tooltipster

I'm using Tooltipster which seems to be a nice jquery plugin. 我正在使用Tooltipster ,它似乎是一个不错的jquery插件。

Regardless I need to have my tooltips dynamic, which I don't believe should be that difficult. 无论如何,我都需要保持动态的工具提示,我认为应该没有那么困难。 However I wrote a script and maybe it's because I'm tired or I don't know the simplest of javascript. 但是我写了一个脚本,也许是因为我累了或者我不了解最简单的javascript。 Probably a combination of both. 可能两者兼而有之。

I can't seem to get around this particular error. 我似乎无法解决这个特定错误。 TypeError: $(...).tooltipster is not a function. TypeError:$(...)。tooltipster不是函数。

Here is the basic javascript code: 这是基本的JavaScript代码:

$("img#box_image[data-img-number]").hover(function(e) {
e.preventDefault();
        i = $(this).attr("data-img-number");
        var w = "http://trailerbrokerimages.s3.amazonaws.com/pics/" + i  ;
        window.console.log('before tool');
        window.console.log('before tool ' +w);
        tool(w);
});
var tool = function (w) {
$('.tooltip_two').tooltipster({content: $('<span><img   style="height:191px;                                                                                width:256px;"src="http://trailerbrokerimages.s3.amazonaws.com/pics/'+w+'" /></span>')});

An example of the code can be found at http://www.trailerbroker.com/go/listings/view/219 可以在http://www.trailerbroker.com/go/listings/view/219上找到该代码的示例

I suspect it's lame mistake on my part, thanks. 我怀疑这是我的la脚错误,谢谢。

You have the same id box_image for multiple elements. 对于多个元素,您具有相同的id box_image

I understand that you're trying to make it unique by appending the data-img-number , but this won't work, as there's no way you can do this at run time unless your explicitly specifying different hover handlers. 我了解您正在尝试通过添加data-img-number使其唯一,但这将无法正常工作,因为除非您明确指定不同的hover处理程序,否则无法在运行时执行此操作。

Instead you could attach the hover handler to a class. 相反,您可以将hover处理程序附加到类。

Add a class="box_image" to your <img /> elements and attach the hover as follows, 在您的<img />元素中添加class="box_image"并将hover ,如下所示,

$(".box_image").hover(//rest of your code here//)

This should give you the desired functionality. 这应该为您提供所需的功能。

I solved this problem by using twitter bootstrap popover. 我通过使用twitter bootstrap popover解决了这个问题。 Don't waste your time with tooltipers. 不要浪费时间使用工具提示。

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

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