Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 静音音频不工作_Jquery_Html_Css_Html5 Audio - Fatal编程技术网

Jquery 静音音频不工作

Jquery 静音音频不工作,jquery,html,css,html5-audio,Jquery,Html,Css,Html5 Audio,这恰好是我的HTML、jQuery和CSS代码。但是点击图像并不会使音频静音 HTML代码 <audio autoplay loop preload="auto"> <source src="assets/music/GoGoRhapsody.m4a" type="audio/mpeg"> </audio> <div id="sound"></div> CSS代码 #sound{ position: absolute

这恰好是我的HTML、jQuery和CSS代码。但是点击图像并不会使音频静音

HTML代码

<audio autoplay loop preload="auto">
    <source src="assets/music/GoGoRhapsody.m4a" type="audio/mpeg">
</audio>

<div id="sound"></div>
CSS代码

#sound{
    position: absolute;
    top: 2%;
    right: 2%;
    width: 2%;
    height: 3%;
    background-image: url(img/mute.png);
}
.muted{
    background-image: url(img/sound.png);
    width: 1%;
}
使用,传递真/假以使其静音/取消静音

完整代码

jQuery('#sound').click(function(){
    if (jQuery(this).hasClass("muted")) {
        jQuery(this).removeClass("muted");
        jQuery('audio').prop("muted", false);
    }else{
        jQuery(this).addClass("muted");
        jQuery('audio').prop("muted", true);
    }
});
此外,您应该使用,它确定是否将任何匹配的元素分配给给定的类。

使用,传递true/false以使其静音/取消静音

完整代码

jQuery('#sound').click(function(){
    if (jQuery(this).hasClass("muted")) {
        jQuery(this).removeClass("muted");
        jQuery('audio').prop("muted", false);
    }else{
        jQuery(this).addClass("muted");
        jQuery('audio').prop("muted", true);
    }
});
此外,您应该使用,它确定是否将任何匹配的元素分配给给定的类。

使用,传递true/false以使其静音/取消静音

完整代码

jQuery('#sound').click(function(){
    if (jQuery(this).hasClass("muted")) {
        jQuery(this).removeClass("muted");
        jQuery('audio').prop("muted", false);
    }else{
        jQuery(this).addClass("muted");
        jQuery('audio').prop("muted", true);
    }
});
此外,您应该使用,它确定是否将任何匹配的元素分配给给定的类。

使用,传递true/false以使其静音/取消静音

完整代码

jQuery('#sound').click(function(){
    if (jQuery(this).hasClass("muted")) {
        jQuery(this).removeClass("muted");
        jQuery('audio').prop("muted", false);
    }else{
        jQuery(this).addClass("muted");
        jQuery('audio').prop("muted", true);
    }
});

此外,您应该使用它来确定是否有任何匹配的元素被分配给给定的类。

我在一个网站上做过一次:

$(".sound").on('click', function(){
    if ($('#player audio').get(0).muted) {
        $('#player audio').get(0).muted = false;
    } else {
        $('#player audio').get(0).muted = true;
    }
});

应该可以正常工作。

我在一个网站上做过一次:

$(".sound").on('click', function(){
    if ($('#player audio').get(0).muted) {
        $('#player audio').get(0).muted = false;
    } else {
        $('#player audio').get(0).muted = true;
    }
});

应该可以正常工作。

我在一个网站上做过一次:

$(".sound").on('click', function(){
    if ($('#player audio').get(0).muted) {
        $('#player audio').get(0).muted = false;
    } else {
        $('#player audio').get(0).muted = true;
    }
});

应该可以正常工作。

我在一个网站上做过一次:

$(".sound").on('click', function(){
    if ($('#player audio').get(0).muted) {
        $('#player audio').get(0).muted = false;
    } else {
        $('#player audio').get(0).muted = true;
    }
});
应该和你一起正常工作