【问题标题】:why this jquery code works under opera only and not under firefox and chrome?为什么这个 jquery 代码只能在 opera 下工作,而不能在 firefox 和 chrome 下工作?
【发布时间】:2013-12-21 02:55:43
【问题描述】:

简单并开始一个新的界面:

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="./style/style.css" />
    <script src="./javascript/jquery-1.10.2.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            var color = $('#title_buttom').css('background-color');
            $('.title_all').mouseover(function(){
                var styles = {
                backgroundColor : '#FF0C55'};
                $('#title_buttom').css( styles );
            });
            $('.title_all').mouseout(function(){
                $('#title_buttom').css('background-color',color);
            });
        });​
    </script>
</head>
<body>
    <div id='all_div'>
        <div id='master'>
            <div id='title_top'>
                <div id='title_home' class='title_all'>Home</div>
                <div id='title_info' class='title_all'>Info</div>
                <div id='title_project' class='title_all'>Projects</div>
                <div id='title_contectus' class='title_all'>Contect us</div>
            </div>
            <div id='title_buttom'></div>
        </div>
    </div>

</body>
    </html>

出于同样的原因,我不知道为什么只有 opera 浏览器可以使用此代码,而 firefox 和 chrome 不能。这是为什么?

link to the css file

【问题讨论】:

  • 试试 $('.title_all').on('mouseout',function(){ $('#title_buttom').css('background-color',color); });我添加了一个答案...猜这应该可以...如果我的帖子适合您,请评论我的帖子

标签: jquery html google-chrome firefox opera


【解决方案1】:

试试这个

$(document).ready(function () {
    var color = $('#title_buttom').css('background-color');
    $('.title_all').on('mouseover',function () {
        var styles = {
            backgroundColor: '#FF0C55'
        };
        $('#title_buttom').css(styles);
    });
    $('.title_all').on('mouseout',function () {
        $('#title_buttom').css('background-color', color);
    });
});

你可以在这里试试这个来检查在你的样式对象中使用背景颜色而不是背景颜色是否有问题。

$(document).ready(function () 
    {
    var color = $('#title_buttom').css('background-color');

    $('.title_all').on('mouseover',function () 
        {
            $('#title_buttom').css('background-color','#FF0C55');
        });

    $('.title_all').on('mouseout',function () 
    {
        $('#title_buttom').css('background-color', color);
    });
});

【讨论】:

  • Opera 浏览器可以很好地配合您的添加/更改,但 Firefox 和 chrome 浏览器与我的代码一样。
  • 这真的有点奇怪^^你用的是什么jquery版本?如果你运行小提琴(就像@Arun P Johny 说的那样),这还会发生吗?
  • 我知道这有点奇怪。我正在使用 我什至尝试将文件夹上传到我的真实站点和浏览器:firefox 和 chrome 仍在这样做问题和歌剧很好。用我的智能手机和其他电脑试过,firefox 和 chrome 没有显示 jquery 效果,而 opera 有。代码中有问题,但我不知道是什么。
  • 我还没有在这个模板中使用php,这只是这个模板的开始,所以我现在只有客户端站点。
  • 对不起...我只是将这个答案与另一个问题混合在一起:D 你可以尝试使用 1.10.1 吗?因为 fiddle 说 1.10.1 是他们在 fiddle atm 中最高的
猜你喜欢
  • 1970-01-01
  • 2011-04-20
  • 1970-01-01
  • 2012-01-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多