inline javascript仅在firefox中执行

问题描述 投票:0回答:1

所以,我有一个简单的脚本,当一个按钮或标签被点击时,改变一个图像。脚本在firefox中工作得很好,但在edge和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.auadvertise(广告)

当点击accordin或旁边的按钮时,我希望图片能改变。

谢谢你

javascript jquery cross-browser
1个回答
0
投票

去掉封装的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');

    });

我不知道为什么这能解决这个问题,因为我在其他一些网站上也有相同的代码。

© www.soinside.com 2019 - 2024. All rights reserved.