$("#mute").click(function(){
$("#audioplayer")[0].muted = $("#audioplayer")[0].muted;
$("#message").text("Volume muted");
})
我需要实现的是当用户再次点击“静音”按钮时,他们会收到另一条带有“未分配音量”的消息,而不是静音,如果再次点击它,则切换回静音,依此类推。
答案 0 :(得分:1)
尝试以下
(function() {
var muted = false;
$("#mute").click(function(){
muted = !muted;
$("#audioplayer")[0].muted = muted;
var msg = muted ? "Volume muted" : "Volume unmuted";
$("#message").text(msg);
});
})();
答案 1 :(得分: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;
})
而不是全局变量,附加到玩家对象的属性可以更好。
希望这有帮助!