0

所以我创建了一个表格,并尝试为其添加鼠标悬停效果,这样我就可以更改单元格的背景颜色。显然,当背景(在样式中)没有设置颜色时,一切都像魅力一样。但是当它出现时,我想不出它是我们的......有什么帮助吗?这是我的代码:

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
 </head>
<script type="text/javascript">
    var link = true;
</script>
<body>
<style type="text/css">
    .tableX td
    {
        width: 33.33%;
        padding: 5px;
        font-family: 'Sans Serif',segoe UI light, Century Gothic;
        color: #FFFFFF;

    }
        .tableX td.largeLightBlue
        {
            height: 150px;
            -moz-border-radius: 7px;
            -webkit-border-radius: 7px;
            border-radius: 7px;
            width: 33.33%;
            font-size: 18px;
            background: linear-gradient(#1ba3c7, #13738C);
            text-align: left;
            font-family: 'Segoe UI','Century Gothic', sans-serif;
            vertical-align: text-top;
            padding-left: 10px;
            cursor: pointer;
        }
        .tableX td.largeGreen
        {
            height: 150px;
            -moz-border-radius: 7px;
            -webkit-border-radius: 7px;
            border-radius: 7px;
            width: 33.33%;
            font-size: 18px;
            background: linear-gradient(#35a44f, #297E3D);
            text-align: left;
            font-family: 'Segoe UI','Century Gothic', sans-serif;
            vertical-align: text-top;
            padding-left: 10px;
            cursor: pointer;
        }
        .tableX td.largeBlue
        {
            height: 150px;
            -moz-border-radius: 7px;
            -webkit-border-radius: 7px;
            border-radius: 7px;
            width: 33.33%;
            font-size: 18px;
            background: linear-gradient(#0C63CD, #07366F);
            text-align: left;
            font-family: 'Segoe UI','Century Gothic', sans-serif;
            vertical-align: text-top;
            padding-left: 10px;
            cursor: pointer;
        }

    .tableX
    {
        width: 740px;
        border-collapse: separate;
        border-spacing: 10px;
    }
</style>
<table class="tableX">
    <tr>
        <td onmouseover="style.backgroundColor='#E01B6A';" onmouseout="style.backgroundColor='#FAD957';" onclick="if (link) window.location ='http://www.yahoo.com'" class="largeLightBlue"  >
            <b>Some sample text</b><br />
            <ul>
                <li style="font-size: 12px; color: #ffffff; vertical-align: text-top;">Bullet one</li>
                <li style="font-size: 12px; color: #ffffff; vertical-align: text-top;">Bullet two</li>
                <li style="font-size: 12px; color: #ffffff; vertical-align: text-top;">Bullet three</li>
            </ul>
        </td>
        <td onclick="if (link) window.location ='http://www.google.com'" class="largeGreen">
            <b>Second Sample text</b>
            <ul>
                <li style="font-size: 12px; color: #ffffff; vertical-align: text-top;">Bullet one</li>
                <li style="font-size: 12px; color: #ffffff; vertical-align: text-top;">Bullet two</li>
                <li style="font-size: 12px; color: #ffffff; vertical-align: text-top;">Bullet three</li>
                <li style="font-size: 12px; color: #ffffff; vertical-align: text-top;">Bullet four</li>
            </ul>
        </td>
        <td onclick="if (link) window.location ='http://www.bing.com'" class="largeBlue" >
            <b>Third Sample Box</b>
            <ul>
                <li style="font-size: 12px; color: #ffffff; vertical-align: text-top;">Bullet one</li>
                <li style="font-size: 12px; color: #ffffff; vertical-align: text-top;">Bullet two</li>
            </ul>
        </td>
    </tr>

</table>

</body>
</html>
4

1 回答 1

0

onmouseover您只针对您在 CSS 中使用的一个background-color,而不是background属性。设置style.background而不是style.backgroundColor解决问题。JSFiddle 示例

于 2013-04-23T15:49:14.503 回答