首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在鼠标悬停时突出显示不相邻的表格单元格?

问如何在鼠标悬停时突出显示不相邻的表格单元格?
EN

Stack Overflow用户
提问于 2011-07-28 00:26:14
回答 1查看 313关注 0票数 0

我正在尝试为循环风格的锦标赛设置鼠标悬停突出显示效果,以便当有人将鼠标放在球员A对球员B的结果上时,该单元格以及显示球员B对球员A的结果的单元格都会突出显示。为了说明这一点,这里是我想突出显示的页面:http://yppc.zzl.org/groups.html。我还没有找到一个可以同时突出显示不相邻单元格的鼠标悬停脚本。我在另一个网站上看到了这种影响,但不幸的是,联盟没有开会,比分已经被记下来了。

感谢您所能提供的任何帮助!

EN

回答 1

Stack Overflow用户

发布于 2011-07-28 00:52:36

尝试如下所示:

代码语言:javascript
复制
<html>
    <head>
        <script>
            function hl(cell, enable)
            {
                var rIndex = cell.cellIndex;
                var cIndex = cell.parentNode.rowIndex;
                var cell2 = cell.parentNode.parentNode.rows[rIndex].cells[cIndex];

                if (enable) {
                    cell.style.backgroundColor = '#000';
                    cell2.style.backgroundColor = '#000';
                } else {
                    cell.style.backgroundColor = '#fff';
                    cell2.style.backgroundColor = '#fff';
                }
            }
        </script>
    </head>
    <body>
        <table border="1">
            <tr>
                <td></td>
                <td>A</td>
                <td>B</td>
                <td>C</td>
            </tr>
            <tr>
                <td>A</td>
                <td></td>
                <td onmouseover="hl(this, true)" onmouseout="hl(this, false)">A:B</td>
                <td onmouseover="hl(this, true)" onmouseout="hl(this, false)">A:C</td>
            </tr>
            <tr>
                <td>B</td>
                <td onmouseover="hl(this, true)" onmouseout="hl(this, false)">B:A</td>
                <td></td>
                <td onmouseover="hl(this, true)" onmouseout="hl(this, false)">B:C</td>
            </tr>
            <tr>
                <td>C</td>
                <td onmouseover="hl(this, true)" onmouseout="hl(this, false)">C:A</td>
                <td onmouseover="hl(this, true)" onmouseout="hl(this, false)">C:B</td>
                <td></td>
            </tr>
        <table>
    </body>
</html>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6847872

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档