Javascript 禁用和重新启用功能,静音和取消静音

Javascript 禁用和重新启用功能,静音和取消静音,javascript,jquery,function,Javascript,Jquery,Function,您好,我试图禁用一个按钮点击功能,然后再次启用它,一旦另一个按钮被点击,我已经尝试解除绑定,但我没有得到任何地方 有什么建议可以让我做这件事吗 代码: 提前感谢您的建议。好的,我是这样理解的: -在第一页上,用户可以单击静音/取消静音按钮,在浏览所有其他页面/幻灯片时应保存该按钮 下面是一个代码: <!doctype> <html lang="en"> <head> <meta http-equiv="Content-type"

您好,我试图禁用一个按钮点击功能,然后再次启用它,一旦另一个按钮被点击,我已经尝试解除绑定,但我没有得到任何地方 有什么建议可以让我做这件事吗

代码:


提前感谢您的建议。

好的,我是这样理解的: -在第一页上,用户可以单击静音/取消静音按钮,在浏览所有其他页面/幻灯片时应保存该按钮

下面是一个代码:

<!doctype>
<html lang="en">
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8">
        <title></title>
        <!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

        <!-- jQuery library -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

        <!-- Latest compiled JavaScript -->
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    </head>
    <body>
        <button id="mute">Mute</button>
        <button id="unmute">Unmute</button>
        <button id="reloadPage">Reload Page</button>
        <script type="text/javascript">

            //get variable from local variables or set to false(you can change it to TRUE if you like to mute on page load) by default
            var isMuted = localStorage.getItem("IsMuted")||false;

            //mute button onclick method
            $(document).on('click','#mute',function(e){
                isMuted = true;
                //save to local variables
                localStorage.setItem("IsMuted", isMuted);
            }); 

            //unmute button onclick method
            $(document).on('click','#unmute',function(e){
                isMuted = false;
                //save to local variables
                localStorage.setItem("IsMuted", isMuted);
            }); 

            //reload page. also you can use F5 or Ctrl+F5
            $(document).on('click','#reloadPage',function(e){
                location.reload();
            });

            $(document).ready(function(){
                alert("IsMuted = "+isMuted);

                //you can encapsulate this into separate function and bind to show-next-slide button                
                if(isMuted)
                {
                    return;
                }
                else
                {
                    //get clip id by class name or another suitable method
                    PlayMyCoolMusic(clipId);
                }
            });



            function PlayMyCoolMusic(clipId)
            {
                //your audio player logic here

            }
        </script>
    </body>
</html>

哑巴
取消静音
重新加载页面
//默认情况下,从局部变量获取变量或设置为false(如果希望在页面加载时静音,可以将其更改为TRUE)
var ismute=localStorage.getItem(“ismute”)| | false;
//静音按钮点击法
$(文档)。在('单击','静音')上,函数(e){
Ismute=true;
//保存到局部变量
setItem(“Ismute”,Ismute);
}); 
//取消静音按钮onclick方法
$(文档).on('单击','取消静音'),函数(e){
Ismute=假;
//保存到局部变量
setItem(“Ismute”,Ismute);
}); 
//重新加载页面。也可以使用F5或Ctrl+F5
$(文档).on('单击','重新加载页面'),函数(e){
location.reload();
});
$(文档).ready(函数(){
警报(“IsMuted=“+IsMuted”);
//您可以将其封装到单独的函数中,并绑定到“显示下一张幻灯片”按钮
如果(isMuted)
{
返回;
}
其他的
{
//通过类名或其他合适的方法获取剪辑id
playmcoolmusic(clipId);
}
});
功能播放音乐(clipId)
{
//你的音频播放器逻辑在这里
}

使用此功能,即使页面已重新加载,您也可以保存静音/取消静音状态。

您是否尝试过.off()函数?静音按钮是否应仅静音或停止播放。按下静音键时,您只需将音频设置为循环,并停止/将音量设置为0即可。或者您可以设置一些bool值,该值可以通过mute/unmute设置,如果为true,则在函数开始时调用return。不,我还没有尝试过。on()和.off()我尝试现在@maximelian1986静音按钮应该停止soundListen功能静音或暂停它依次没有声音会播放,然后当取消静音按钮被按下时,它应该再次启用soundListen功能,然后它会播放相应的音频,这取决于身体类别。on()或。off()是网站背景音乐,还是游戏音乐?我的意思是你根本就不需要声音监听功能。您可以在启动/加载时启动循环音乐播放,并在按下按钮时停止/静音。然后你在body处用类名更改音乐,所以你从某个地方设置了那个类。在同一时刻更改音频剪辑不是更容易吗?所以,如果您描述更多关于您的逻辑和音乐播放流程的信息,我可以向您推荐更理想的选择。
setInterval(function soundListen() {
    if ($("body").hasClass("fp-viewing-1")) {
        audio1.play();

    } else {
        audio1.pause();
        audio1.currentTime = 0;
    }

    if ($("body").hasClass("fp-viewing-2")) {
        audio2.play();
    } else {
        audio2.pause();
        audio2.currentTime = 0;
    }

    if ($("body").hasClass("fp-viewing-3")) {
        audio3.play();
    } else {
        audio3.pause();
        audio3.currentTime = 0;
    }
}, 100);
<!doctype>
<html lang="en">
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8">
        <title></title>
        <!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

        <!-- jQuery library -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

        <!-- Latest compiled JavaScript -->
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    </head>
    <body>
        <button id="mute">Mute</button>
        <button id="unmute">Unmute</button>
        <button id="reloadPage">Reload Page</button>
        <script type="text/javascript">

            //get variable from local variables or set to false(you can change it to TRUE if you like to mute on page load) by default
            var isMuted = localStorage.getItem("IsMuted")||false;

            //mute button onclick method
            $(document).on('click','#mute',function(e){
                isMuted = true;
                //save to local variables
                localStorage.setItem("IsMuted", isMuted);
            }); 

            //unmute button onclick method
            $(document).on('click','#unmute',function(e){
                isMuted = false;
                //save to local variables
                localStorage.setItem("IsMuted", isMuted);
            }); 

            //reload page. also you can use F5 or Ctrl+F5
            $(document).on('click','#reloadPage',function(e){
                location.reload();
            });

            $(document).ready(function(){
                alert("IsMuted = "+isMuted);

                //you can encapsulate this into separate function and bind to show-next-slide button                
                if(isMuted)
                {
                    return;
                }
                else
                {
                    //get clip id by class name or another suitable method
                    PlayMyCoolMusic(clipId);
                }
            });



            function PlayMyCoolMusic(clipId)
            {
                //your audio player logic here

            }
        </script>
    </body>
</html>