简体   繁体   English

如何解决“script.js”不起作用的问题

[英]How do I fix problem with 'script.js' not working

Basically one of my scripts work but the other one doesn't.基本上我的一个脚本有效,但另一个无效。 I am trying to customize the play button functions with javascript but whenever I try to load the script it seems like the script has no effect on the video.我正在尝试使用 javascript 自定义播放按钮功能,但是每当我尝试加载脚本时,脚本似乎对视频没有影响。

I have checked the code itself and even went back to the index.html to see if I made any errors with the tags.我已经检查了代码本身,甚至返回到 index.html 以查看我是否对标签有任何错误。 I also found out after inspecting the script is not there but it's declared in the index.html.在检查脚本后我还发现不存在但它在 index.html 中声明。

 index.html





    <div class="container">


    <div class="c-video">
                        <video class="video" src="stranding.mp4"></video>
                        <div class="controls">
                                <div class="orange-bar"></div>
                                    <div class="orange-juice"></div>

                    <div class="buttons">
                        <button id="play-pause"></button></div>

                   </div>

                </div>
            </div>

            <script src="script.js"></script>
            <script src="alert.js"></script>



________________________________________________________________________
        var video = document.querySelector("video");
        var juice = document.querySelector("orange-juice");
        var btn = document.getElementById("play-pause");




        function togglePlayPause() {
            if(video.paused){
                btn.className = "pause";
                video.play();

         } else {

            btn.className = "play";
            video.pause();
         } 
        }

        btn.onclick = funtion() {
            togglePlayPause();
        };


    ________________________________________________________
    stye.css 

    .buttons button.play:before {
        content: "\fo4b";
    }

    .buttons button.pause:before {
        content: "\f04c";
    }

    .orange-bar{
        height: 10px;
        top: 0;
        left: 0;
        width: 100%;
    }

    .orange-juice{
        height: 10px;
        background-color: silver;
    }

I want the script to cause the video to play/pause but it doesn't.我希望脚本使视频播放/暂停,但它没有。

You are incorrectly taking the reference of the Play/Pause button.您错误地引用了播放/暂停按钮。 Instead of:代替:

document.getElementById(".play-pause");

use

document.getElementById("play-pause");

You are using the " . " class selector in document.getElementsById您正在使用document.getElementsById的“ . ”类选择器

var btn = document.getElementById(".play-pause");

Without seeing the HTML and knowing exactly what is going on, try在没有看到 HTML 并且不知道发生了什么的情况下,尝试

var btn = document.getElementById("play-pause");

暂无
暂无

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

相关问题 如何修复“script.js:5 Uncaught TypeError: ...”JavaScript 错误 - How to fix "script.js:5 Uncaught TypeError: ..." JavaScript error 如何使用 dotenv 在 script.js 文件中隐藏我的 API 密钥 - How do I hide my API key in script.js file using dotenv 如何在Eclipse控制台中运行script.js? - How can I run script.js in Eclipse console? 我将模板集成到我的 angular 项目中,但在这两个文件中遇到了问题:core.min.js 和 script.js - I integrated a template into my angular project and I encountered a problem in these two files : core.min.js and script.js 浏览器如何访问这个脚本<script hrf="host/script.js">? - How browser access to this script <script hrf="host/script.js">? 我的script.js和mail.php不匹配 - my script.js and mail.php do not match 如何在$ script.js库中为文件加载设置http RequestHeader? - How can I set the http RequestHeader for a file load in the $script.js library? 如何使用 script.js 在 html 上显示 json 数据? - How can I display json data on the html using script.js? 如何使用来自 POST 请求的数据通过 script.js 文件操作 DOM - How can I use data from POST request to manipulate the DOM using a script.js file 如何将 DOM JavaScript 添加到我的 script.js 中,以便在提交 info(firstname, lastname, and age) 时,它会在主页上显示为一个句子? - How do I add DOM JavaScript to my script.js so when info(firstname, lastname, and age) is submitted, it displays on the main page as a sentence?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM