[关闭]
@1002522146 2019-11-25T07:44:59.000000Z 字数 356 阅读 380

[].forEach.call

未分类


音频互斥

  1. let audios = document.getElementsByTagName('audio');
  2. function pauseAll() {
  3. let self = this;
  4. [].forEach.call(audios, (i) => {
  5. // 将audios中其他的audio全部暂停
  6. i !== self && i.pause();
  7. });
  8. }
  9. [].forEach.call(audios, (i) => {
  10. i.addEventListener('play', pauseAll.bind(i));
  11. });
  12. document.getElementsByTagName 返回的 HTMLCollection 不能用foreach
  13. document.querySelectorAll 返回的 NodeList 可以用foreach
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注