ElementById('modal-template'); // 遍历下载选项并添加点击事件监听器 downloadLinks.forEach((downloadLink) => { downloadLink.addEventListener('click', (event) => { // 阻止默认行为 event.preventDefault(); // 获取下载类型参数的值 const downloadType = downloadLink.getAttribute('data-type'); // 创建弹出窗口 const modal = modalTemplate.cloneNode(true); modal.removeAttribute('style'); // 将弹出窗口添加到页面中 document.body.appendChild(modal); // 获取 iframe 元素并设置 src 属性 const downloadFrame = modal.querySelector('#download-frame'); downloadFrame.src = `/video/down/80564/0/${downloadType}`; // 添加关闭事件监听器 modal.addEventListener('click', (event) => { // 如果用户点击了弹出窗口以外的区域,关闭弹出窗口 if (event.target === modal) { modal.remove(); } }); // 关闭弹出窗口的函数 const closeModal = () => { modal.remove(); document.body.classList.remove('modal-open'); }; // 添加关闭按钮的点击事件监听器 const closeButton = modal.querySelector('.close-button'); closeButton.addEventListener('click', closeModal); // 添加背景的点击事件监听器 modal.addEventListener('click', (event) => { if (event.target === modal) { closeModal(); } }); }); });