我有这个代码。这很完美。

<button id="mutebtn2">Mute</button></li>
<script>
mutebtn2 = document.getElementById("mutebtn2");
mutebtn2.addEventListener("click",vidmute2,false);
function vidmute2(){
  if(idle_video.muted){
     idle_video.muted = false;
     mutebtn2.innerHTML = "Mute";
  } else {
     idle_video.muted = true;
     mutebtn2.innerHTML = "Unmute";
  }
}
</script>


此代码使视频静音,可以正常工作。

问题是,我想替换开/关之类的图像的按钮。我试过了,但是代码似乎是我的错误。
我很感激任何帮助

最佳答案

您可以将<button id="mutebtn2">Mute</button>中的文本替换为img

<button id="mutebtn2"><img src="link-to-image" /></button>


并在您的vidmute2()函数中,而不是用文本img html代替innerHTML

function vidmute2(){
  if(idle_video.muted){
     idle_video.muted = false;
     mutebtn2.innerHTML = "<img src='link-to-image' />";
  } else {
     idle_video.muted = true;
     mutebtn2.innerHTML = "<img src='link-to-image' />";
  }
}

关于javascript - 自定义视频的按钮静音,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30609639/

10-10 22:50