[英]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.