使用 jQuery 查找并添加图像工具提示

发布于 2024-08-31 01:18:19 字数 1267 浏览 1 评论 0原文

好的,我想要完成的是一个简单的工具提示,当您将鼠标悬停在颜色名称上时,会显示该颜色的小图像。 html 标记如下所示:

<label class="colorPicker">
    <input type="radio" checked="" id="20" value="20" name="id[2]">
    <img width="16" height="16" title=" DinoBlack Mat " alt="DinoBlack Mat" src="images/attributes/color/dinoblack_mat.jpg">DinoBlack Mat
</label>
<label class="colorPicker">
    <input type="radio" id="874" value="874" name="id[2]">
    <img width="16" height="16" title="XrayBlue shiny" alt="XrayBlue shiny" src="images/attributes/color/xrayblue_shiny.jpg">XrayBlue shiny
</label>

我正在使用 jQuery 插件 "Tooltip" 并且我'我在我的主 js 文件中添加了以下内容:

$('.colorPicker').tooltip({ 
    track: true,
    delay: 0,
    showURL: false,
    fade: 250,
    bodyHandler: function() {
        return $("<img/>").attr("src", [THE SOURCE FOR THE IMAGE]);
    }
});

这个想法很简单,默认情况下应该隐藏图像。但是,当您将鼠标悬停在文本上时,会显示小缩略图,使您可以轻松识别颜色。 问题是我不知道如何获取缩略图的 src。我不知道如何从所选元素内的 img 中提取 src。我尝试过使用 this 关键字的各种组合,但似乎没有任何效果。

我还尝试将 src 路径作为 rel 属性添加到标签中,但也没有成功。不用说,我也控制 PHP 输出......

我真的希望你能帮助我。我在网上搜索了好几天,没有任何运气。我变得绝望了:D

/Mikkel Lund

Okay, what I'm trying to accomplish is a simple tool tip that, when you hover over the name of a color, shows a little image of that color. The html markup looks like this:

<label class="colorPicker">
    <input type="radio" checked="" id="20" value="20" name="id[2]">
    <img width="16" height="16" title=" DinoBlack Mat " alt="DinoBlack Mat" src="images/attributes/color/dinoblack_mat.jpg">DinoBlack Mat
</label>
<label class="colorPicker">
    <input type="radio" id="874" value="874" name="id[2]">
    <img width="16" height="16" title="XrayBlue shiny" alt="XrayBlue shiny" src="images/attributes/color/xrayblue_shiny.jpg">XrayBlue shiny
</label>

I'm using the jQuery plugin "Tooltip" and I've added following to my main js-file:

$('.colorPicker').tooltip({ 
    track: true,
    delay: 0,
    showURL: false,
    fade: 250,
    bodyHandler: function() {
        return $("<img/>").attr("src", [THE SOURCE FOR THE IMAGE]);
    }
});

The idea is simply that the image should be hidden by default. But when you hover over the text the little thumbnail shows up and makes it easy to recognize the color.
The problem is I haven't got a clue how to get the src for the thumbnail. I don't know how to extract the src from the img inside the selected element. I've tried various combinations using the this keyword, but nothing seemed to work.

I've also tried to add the src path as a rel attribute to the label, but also without any success. Should be needless to say I also control the PHP-output...

I really hope you can help me. I've search the web for days without any luck. I'm getting desperate :D

/Mikkel Lund

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南城旧梦 2024-09-07 01:18:19
$('.colorPicker').tooltip({ 
    track: true,
    delay: 0,
    showURL: false,
    fade: 250,
    bodyHandler: function() {
        return $("<img/>").attr("src", $(this).children('img:first').attr('src'));
    }
});

一切准备就绪:)

$('.colorPicker').tooltip({ 
    track: true,
    delay: 0,
    showURL: false,
    fade: 250,
    bodyHandler: function() {
        return $("<img/>").attr("src", $(this).children('img:first').attr('src'));
    }
});

and you're all set :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文