视频静音/取消静音按钮javaScript [英] Video mute/unmute button javaScript

查看:1619
本文介绍了视频静音/取消静音按钮javaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JavaScript初学者在这里!

JavaScript beginner here!

我正在尝试用javaScript制作视频播放器用于学校项目,但我的静音按钮出现问题。

I am trying to make a video player in javaScript for a school project but I am having trouble with my mute button.

我希望按钮在点击时静音视频,如果再次按下按钮则取消静音。到目前为止,我只能将视频静音并保持静音。

I want the button to mute the video when clicked and unmute if the button is pressed again. So far I have only been able to mute the video and keep it muted.

这是我当前的静音按钮。

Here is my current mute button.

var button = document.getElementById('mute');
    button.onclick = function (){
        video.muted = true;
    };

我尝试了if else语句,但没有成功

I tried an if else statement but it was unsuccessful

var button = document.getElementById('mute');
    button.onclick = function (){

    if (video.muted = false) {    
           video.muted = true;
    }

    else {
        video.muted = false;
    }

    };

感谢您的帮助。

推荐答案

if (video.muted = false) {    
       video.muted = true;
}

这应该是

if (video.muted === false) {    
       video.muted = true;
}

否则else语句永远不会运行,因为你正在设置video.muted每次在if语句中都为false。

Or else the else statement will never run, since you are setting video.muted to false every time in the if statement itself.

这篇关于视频静音/取消静音按钮javaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆