javascript - 渐变颜色 OnMouseOver(禁用样式颜色)???

标签 javascript html css gradient onmouseover

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

<!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>

最佳答案

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

关于javascript - 渐变颜色 OnMouseOver(禁用样式颜色)???,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16169282/

相关文章:

css - CSS specificity中的points是怎么计算的

javascript - 保存时将值返回到 BackBone.js

javascript - 使用 javascript/显示和隐藏选择框

javascript - 为什么 anchor 标记占用额外的空白空间?

javascript - JQuery 滚动在 Internet Explorer 或 Firefox 中不起作用

javascript - 从第一个按钮下拉后移动下一个按钮

html - 在 li 标签中填充

javascript - 防止在 React 渲染组件上使用 CSS 滚动

javascript - jquery 爆炸效果无法正常工作

html - 悬停时显示的背景图像 - 列表项