[英]Show Text on Image Hover
I'm trying to have an image description shown when hovering over the image which is placed in a div ( #web01
). 我正在尝试将
#web01
悬停在放置在div( #web01
)中的图像上时显示图像说明。
I've been toying with the mouseenter
/ mouseleave
and have been able to get text shown but when I link it to a div it doesn't seem to work. 我一直在使用
mouseenter
/ mouseleave
并且能够显示文本但是当我将它链接到div时它似乎不起作用。
It's probably dead easy but i can't see what I'm doing wrong. 这可能很容易,但我看不出我做错了什么。
$(document).ready(function () {
$("#web01").mouseenter(function () {
$("#titel").html('<p class="titel">description</p>');
});
$("#web01").mouseleave(function () {
$("#titel").html('<p class="titel"></p>');
});
})
I think you need something like this: 我想你需要这样的东西:
Assuming you meant to name your element title1
and not titel1
(spelled incorrectly), simply changing the id to title1
fixes the problem. 假设你想要命名你的元素
title1
而不是titel1
(拼写错误),只需将id更改为title1
解决问题。 I've given a working example below. 我在下面给出了一个有效的例子。
<div id="web01" title="myTitle">...</div>
或<img src="..." title="myTitle"/>
将显示本机浏览器标题(工具提示)。
In the example on http://api.jquery.com/mouseenter/ I saw them use this in the function. 在http://api.jquery.com/mouseenter/上的示例中,我看到它们在函数中使用它 。
$(document).ready(function(){
$("#web01").mouseenter(function(){
$("#titel",this).html('description');
});
$("#web01").mouseleave(function() {
$("#titel",this).html('');
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.