I haven't seen this exact question addressed...if it has been, just please point me to it.
我没有看到这个确切的问题......如果有的话,请指出我。
I'm using jquery's ui tooltip. I have one link that when you mouseover it, I'd like to show an image. Nothing has worked for me so far.
我正在使用jquery的ui工具提示。我有一个链接,当你鼠标悬停它时,我想显示一个图像。到目前为止,对我来说没有任何作用。
ui code in header:
标题中的ui代码:
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
HTML:
(see <a id='riverroad' href='#' title='' >image of 1 Maple St.</a>)
code:
$( "#riverroad" ).tooltip({ content: "<img src='./images/myimage.jpg/>" });
Please tell me what I'm doing wrong.
请告诉我我做错了什么。
3 个解决方案
#1
16
try this one :
试试这个:
Html
<a id="riverroad" href="#" title="" >image of 1 Maple St.</a>
JQuery
$( "#riverroad" ).tooltip({ content: '<img src="yourImagePath" />' });
See the working fiddle.
看到工作小提琴。
Jquery 1.9.1 and JqueryUI 1.9.2 are included of course. Check if your image path is correct by the way.
当然包括Jquery 1.9.1和JqueryUI 1.9.2。顺便提一下,检查图像路径是否正确。
Edit : You told me that you're setting the link with jQuery, see this second working example :
编辑:您告诉我您正在使用jQuery设置链接,请参阅第二个工作示例:
Html
<div id="content">
</div>
JQuery
$(document).ready(function() {
$("#content").html('<a id="riverroad" href="#" title="" >image of 1 Maple St.</a>');
$("#content #riverroad").tooltip({ content: '<img src="http://icdn.pro/images/fr/a/v/avatar-barbe-brun-homme-utilisateur-icone-9665-128.png" />' });
});
Here is the new fiddle !
这是新的小提琴!
#2
6
First, you are missing the closing quote of your src
tag. Your code should be :
首先,您缺少src标记的结束引用。你的代码应该是:
$( "#riverroad" ).tooltip({ content: "<img src='./images/myimage.jpg' />" });
Moreover, this should be working with the following code as shown on jQueryUI's website :
此外,这应该使用jQueryUI网站上显示的以下代码:
HTML :
<a id='riverroad' href='#' title='' >image of 1 Maple St.</a>
JS :
<script>
$(function() {
$( document ).tooltip({
items: "a",
content: function() {
if (element.attr('id') === 'riverroad') {
return "<img class='map' src='./images/myimage.jpg' />";
}
}
});
});
</script>
Here is a demo on jsFiddle : http://jsfiddle.net/QgPEw/1/
这是关于jsFiddle的演示:http://jsfiddle.net/QgPEw/1/
#3
2
Just pass the HTML content directly in title and you'll be fine.
只需直接在标题中传递HTML内容,您就可以了。
<a id="riverroad" href="#" title="<img src='http://icdn.pro/images/fr/a/v/avatar-barbe-brun-homme-utilisateur-icone-9665-128.png'" >image of 1 Maple St.</a>
Just remember to use single quotes inside title.
只记得在标题中使用单引号。
#1
16
try this one :
试试这个:
Html
<a id="riverroad" href="#" title="" >image of 1 Maple St.</a>
JQuery
$( "#riverroad" ).tooltip({ content: '<img src="yourImagePath" />' });
See the working fiddle.
看到工作小提琴。
Jquery 1.9.1 and JqueryUI 1.9.2 are included of course. Check if your image path is correct by the way.
当然包括Jquery 1.9.1和JqueryUI 1.9.2。顺便提一下,检查图像路径是否正确。
Edit : You told me that you're setting the link with jQuery, see this second working example :
编辑:您告诉我您正在使用jQuery设置链接,请参阅第二个工作示例:
Html
<div id="content">
</div>
JQuery
$(document).ready(function() {
$("#content").html('<a id="riverroad" href="#" title="" >image of 1 Maple St.</a>');
$("#content #riverroad").tooltip({ content: '<img src="http://icdn.pro/images/fr/a/v/avatar-barbe-brun-homme-utilisateur-icone-9665-128.png" />' });
});
Here is the new fiddle !
这是新的小提琴!
#2
6
First, you are missing the closing quote of your src
tag. Your code should be :
首先,您缺少src标记的结束引用。你的代码应该是:
$( "#riverroad" ).tooltip({ content: "<img src='./images/myimage.jpg' />" });
Moreover, this should be working with the following code as shown on jQueryUI's website :
此外,这应该使用jQueryUI网站上显示的以下代码:
HTML :
<a id='riverroad' href='#' title='' >image of 1 Maple St.</a>
JS :
<script>
$(function() {
$( document ).tooltip({
items: "a",
content: function() {
if (element.attr('id') === 'riverroad') {
return "<img class='map' src='./images/myimage.jpg' />";
}
}
});
});
</script>
Here is a demo on jsFiddle : http://jsfiddle.net/QgPEw/1/
这是关于jsFiddle的演示:http://jsfiddle.net/QgPEw/1/
#3
2
Just pass the HTML content directly in title and you'll be fine.
只需直接在标题中传递HTML内容,您就可以了。
<a id="riverroad" href="#" title="<img src='http://icdn.pro/images/fr/a/v/avatar-barbe-brun-homme-utilisateur-icone-9665-128.png'" >image of 1 Maple St.</a>
Just remember to use single quotes inside title.
只记得在标题中使用单引号。