0
$("#mute").click(function(){
        $("#audioplayer")[0].muted = $("#audioplayer")[0].muted; 
        $("#message").text("Volume muted");
    })

我需要实现的是,当用户再次单击“静音”按钮时,他们将收到另一条带有“音量未静音”的消息,而不是静音,如果他再次单击它,则切换回静音,依此类推。

4

2 回答 2

1

尝试以下

(function() {
  var muted = false;
  $("#mute").click(function(){
    muted = !muted;
    $("#audioplayer")[0].muted = muted;

    var msg = muted ? "Volume muted" : "Volume unmuted";
    $("#message").text(msg);
  });
})();
于 2012-04-07T14:50:56.430 回答
1

我会这样尝试:

var playerIsMuted = false;

$("#mute").click(function(){
   if (playerIsMuted){
       $("#audioplayer")[0].muted = false;
       $("#message").text("Volume unmuted");
   }else{
       $("#audioplayer")[0].muted = true;
       $("#message").text("Volume muted");
  }
  playerIsMuted = !playerIsMuted;
})

而不是全局变量,附加到播放器对象的属性可以更好。

希望这可以帮助!

于 2012-04-07T14:54:26.313 回答