简体   繁体   English

OnClick功能在我的网站上不起作用

[英]OnClick function isn't working on my website

I am new to JS. 我是JS新手。 I re-created what i want into JSFiddle here: https://jsfiddle.net/t5fq5zjj/ 我在这里重新创建了我想要的JSFiddle: https ://jsfiddle.net/t5fq5zjj/

Basically, it's working fine in jsF, but when I apply this into my code, it isn't working. 基本上,它在jsF中可以正常工作,但是当我将其应用于代码中时,它将无法正常工作。 When I click on .card1 (or whatever) nothing will happen to it. 当我单击.card1 (或其他)时,什么都不会发生。 So i want to ask, do I have this right? 所以我想问,我有这个权利吗?

<head>
    ...
    <!-- js -->
    <script src="js/jquery-2.1.4.min.js"></script>
    ...
    <script>
        $(function () {
            $(".icon_card1").click(function () {
        $(".card1bg").css('opacity', '1');
            });
        });
    </script>
</head>
<body>
    ...
    <div class="content">
        <div class="card1">
            <div class="image_card1"></div>
            <div class="icon_card1"><img src="img/arrow.png"></div>
        </div>
    </div>
    ...
    <div class="card1bg">
        <video autoplay  poster="img/background.png" id="bgvid" loop>
            <source src="img/background.mp4" type="video/mp4">
        </video>
    </div>
    ...
</body>

It isn't working in my code, but it is in jsFiddle. 它在我的代码中不起作用,但是在jsFiddle中。 Thanks for your time. 谢谢你的时间。

EDIT: I loaded all code to my hosting, so here you can check it: http://hdesign.comehere.cz/ 编辑:我将所有代码加载到我的托管,所以在这里您可以检查它: http : //hdesign.comehere.cz/

Wrap your JavaScript code within a document ready function. 将您的JavaScript代码包装在文档就绪函数中。

$( document ).ready(function() {
    $(".card1").click(function () {
        $(".card1_content").css('background', 'red');
    });

    $(".card2").click(function () {
        $(".card1_content").css('background', 'aqua');
    });
});

I try to test your project on your specified hosting , but I see that jquery file does not load properly (error 404). 我尝试在指定的托管上测试您的项目,但我发现jquery文件无法正确加载(错误404)。 Try to check your jquery filepath and file location 尝试检查您的jQuery文件路径和文件位置

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM