【问题标题】:inline javascript only executing in firefox内联 javascript 仅在 Firefox 中执行
【发布时间】:2020-09-05 17:00:10
【问题描述】:

所以我有一个简单的脚本可以在单击按钮或选项卡时更改图像。该脚本在 Firefox 中运行良好,但我什至无法在边缘和 chrome 中执行我的脚本中的任何内容。除了一些警告和一些错误之外,控制台日志中没有任何帮助。有人可以帮我解决这个问题吗?

<script type="text/javascript">
jQuery(function($){
        $('#specs_button1').click(function() {
            $('#the_image').attr('src',templateUrl+'/images/GRAdSpecs/DPS-min.jpg');              
        });
        $('#specs_button2').click(function() {
            $('#the_image').attr('src',templateUrl+'/images/GRAdSpecs/FP-min.jpg');
        });
        $('#specs_button3').click(function() {
            $('#the_image').attr('src', templateUrl+'/images/GRAdSpecs/HP-min.jpg');
        });
        $('#specs_button4').click(function() {
            $('#the_image').attr('src', templateUrl+'/images/GRAdSpecs/HP_vertical-min.jpg');
        });
        $('#specs_button5').click(function() {
            $('#the_image').attr('src', templateUrl+'/images/GRAdSpecs/QP_horizontal.jpg');
        });
        $('#specs_button6').click(function() {
            $('#the_image').attr('src', templateUrl+'/images/GRAdSpecs/QP-min.jpg');
        });

        $('#specs1').click(function() {
            $('#the_image').attr('src', templateUrl+'/images/GRAdSpecs/DPS-min.jpg');
        });
        $('#specs2').click(function() {
            $('#the_image').attr('src',templateUrl+'/images/GRAdSpecs/FP-min.jpg');
            console.log("Button 2");
        });
        $('#specs3').click(function() {
            $('#the_image').attr('src', templateUrl+'/images/GRAdSpecs/HP-min.jpg');
        });
        $('#specs4').click(function() {
            $('#the_image').attr('src', templateUrl+'/images/GRAdSpecs/HP_vertical-min.jpg');
        });
        $('#specs5').click(function() {
            $('#the_image').attr('src', templateUrl+'/images/GRAdSpecs/QP_horizontal.jpg');
        });
        $('#specs6').click(function() {
            $('#the_image').attr('src', templateUrl+'/images/GRAdSpecs/QP-min.jpg');
        });
});
</script>

网址:greenreview.com.au/advertise

点击accordin或旁边的按钮时,我想改变图像

谢谢

【问题讨论】:

  • window.onload = jQuery(function($){ window.onload =。
  • 哦,啊,我拼命想从这个脚本中获取任何内容到我的页面中,我在 console.log 消息中添加了它。让我清理一下。我的道歉

标签: javascript jquery cross-browser


【解决方案1】:

去掉封装的jquery函数好像解决了这个问题。

        var $ = jQuery;
    $('#specs_button1').click(function() {
        $('#the_image').attr('src',templateUrl+'/images/GRAdSpecs/DPS-min.jpg');

    });
    $('#specs_button2').click(function() {
        $('#the_image').attr('src',templateUrl+'/images/GRAdSpecs/FP-min.jpg');

    });
    $('#specs_button3').click(function() {
        $('#the_image').attr('src', templateUrl+'/images/GRAdSpecs/HP-min.jpg');

    });
    $('#specs_button4').click(function() {
        $('#the_image').attr('src', templateUrl+'/images/GRAdSpecs/HP_vertical-min.jpg');

    });
    $('#specs_button5').click(function() {
        $('#the_image').attr('src', templateUrl+'/images/GRAdSpecs/QP_horizontal.jpg');

    });
    $('#specs_button6').click(function() {
        $('#the_image').attr('src', templateUrl+'/images/GRAdSpecs/QP-min.jpg');

    });

    $('#specs1').click(function() {
        $('#the_image').attr('src', templateUrl+'/images/GRAdSpecs/DPS-min.jpg');

    });
    $('#specs2').click(function() {
        $('#the_image').attr('src',templateUrl+'/images/GRAdSpecs/FP-min.jpg');

    });
    $('#specs3').click(function() {
        $('#the_image').attr('src', templateUrl+'/images/GRAdSpecs/HP-min.jpg');

    });
    $('#specs4').click(function() {
        $('#the_image').attr('src', templateUrl+'/images/GRAdSpecs/HP_vertical-min.jpg');

    });
    $('#specs5').click(function() {
        $('#the_image').attr('src', templateUrl+'/images/GRAdSpecs/QP_horizontal.jpg');

    });
    $('#specs6').click(function() {
        $('#the_image').attr('src', templateUrl+'/images/GRAdSpecs/QP-min.jpg');

    });

我不确定为什么会修复它,因为我在其他一些网站上有确切的代码

【讨论】:

    猜你喜欢
    • 2017-11-25
    • 1970-01-01
    • 1970-01-01
    • 2011-11-03
    • 1970-01-01
    • 2021-06-02
    • 2016-05-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多