jquery - HTML 表格和悬停图像和链接

标签 jquery html css html-table hover

我有一个客户,他有一个 HTML 表格布局(我知道),其中一行有图像,下一行有相应的文本链接。图像和文本都是单独的超链接,样式没有下划线(此处的代码中未显示)。

<table>
<tr>
<td><a href="product1"><img src="productimage1.jpg" /></a></td>
<td><a href="product2"><img src="productimage2.jpg" /></a></td>
<td><a href="product3"><img src="productimage3.jpg" /></a></td>
<td><a href="product4"><img src="productimage4.jpg" /></a></td>
</tr>
<tr>
<td><a href="product1">Product1</a></td>
<td><a href="product2">Product2</a></td>
<td><a href="product3">Product3</a></td>
<td><a href="product4">Product4</a></td>
</tr>
</table>

我知道在CSS中,下划线悬停可以在文本链接上实现。问题是,用户是否可以将鼠标悬停在图像(在表行中)上并使相应的文本链接(在下一个表行中)带有下划线?例如,如果我将鼠标悬停在“productimage3.jpg”上,那么我希望 Product3 链接带有下划线(当悬停关闭时不带下划线)。我想用 jQuery 可以做一些事情,但我是一个 jQuery 菜鸟。

最佳答案

CSS:

.hovered {
    text-decoration : underline;
}

jQuery:

$('a').hover(function(){
    $('a[href="' + $(this).attr('href') + '"]').toggleClass('hovered');
});

演示:http://jsfiddle.net/Gs5Q5/1/

关于jquery - HTML 表格和悬停图像和链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14692828/

相关文章:

html - 背景颜色与文字颜色相同

HTML/CSS 导航栏格式问题

javascript - 如何使用 JQuery 和 Translate 在屏幕中动态居中 div

jquery - Chrome 中选择选项元素上的单击事件

javascript - 重复 onload 动画 onclick - Raphael Javascript SVG 动画

html - 为 flash 和 w3c 嵌入标签

javascript - 简单的基于 jQTouch Form 的产品选择器

javascript - 删除所选选项中的重复元素

css - 更改为@font-face 后,列表被隔开?

javascript - 您应该将 vb.net 应用程序专用的 html 文件放在 vb.net 应用程序的哪个文件夹中?