如何使用js更改html中的控件列表?

问题描述 投票:0回答:1

1。所以我想将controlist="nodownload"更改为controlist="download"使用Javascript加载页面后。

<html>
   <body>
      <audio id="preview"controls=" " controlist="nodownload" 
      <source src="horse.mp3" type="audio/ogg">
      </audio>
   </body>
</html>

2.my javascript:

window.onload = function() {
  var x = document.getElementsByid("preview"); 
  x.setAttribute("controlist", "download");
}

这不起作用,因此您可以纠正我的错误以使其起作用。[Violation] 'load' handler took 23639ms[Violation] 'setTimeout' handler took 73ms[Violation] 'visibilitychange' handler took 762ms

javascript html html5-audio
1个回答
0
投票

更改为:

window.onload = function() {
  var x = document.getElementsByid("preview"); 
  x.setAttribute("controlslist", "download");
}

至:

window.onload = function() {
  var x = document.getElementsByid("preview"); 
  x.setAttribute("controlist", "download");
}

您写错x.setAttribute("controlist", "download");

示例:

window.onload = function() {
  var x = document.getElementById("preview"); 
  x.setAttribute("controlist", "download");
}
<html>
   <body>
      <audio id="preview"controls=" " controlist="nodownload" 
      <source src="horse.mp3" type="audio/ogg">
      </audio>
   </body>
</html>
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.