JavaScript:将所有包含“ * sometext *”的表td条目加粗鼠标悬停时 [英] JavaScript: Bold all table td entries which contain "*sometext*" on mouse-over

查看:35
本文介绍了JavaScript:将所有包含“ * sometext *”的表td条目加粗鼠标悬停时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在某些页面上有一个元素。它包含一些带有单元格的表行,其中包含 href s。

I have a table element on some page. It contains some table rows with cells, containing hrefs.

我的目标是:当我将鼠标指向上方时一些 href 带有文本 sometext,所有包含此 sometext文本的表href都将变为粗体。

My target is: when I point mouse cursor over some href with text "sometext", all table hrefs that contain this "sometext" text to become with bold text. On mouse-out, all hrefs should go to normal state.

谢谢,
Venelin

Thanks, Venelin

推荐答案

使用jQuery(您说可以接受)可能是这样的:

Using jQuery (which you said may be acceptable) it could be something like this:

$(document).ready(function(){
   $('td > a').hover(
       function() {
           $('td > a:contains("' + this.innerHTML + '")').css('font-weight', 'bold')
       },
       function() {
           $('td > a').css('font-weight', 'normal')
       }
   )
})

演示: http://jsfiddle.net / 2ATc5 / 3 /

当鼠标进入TD中的锚点时,代码将查找TD中具有相同文本并将其加粗的所有锚点。

When mouse enters anchor within TD - code looks for all anchors within TDs that have the same text and bolds them.

当鼠标离开锚点时,字体粗细会恢复正常。

When mouse leaves the anchor - font-weight returns to normal.

这篇关于JavaScript:将所有包含“ * sometext *”的表td条目加粗鼠标悬停时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆