1 回答

TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊
目前尚不清楚您想對(duì)視頻本身做什么。但是,我首先會(huì)嘗試擺脫 CSS。如果您確實(shí)想撕下視頻,然后將其包裝在您自己的 HTML 中并將其放回原來(lái)的位置,您可以這樣做:
// Get reference to the video element
const videoElement = document.getElementsByTagName('video')[0];
// Clone the element
const videoClone = videoElement.cloneNode(true);
// Create your new container
const videoContainer = document.createElement('div');
// Do what you want with the new container
const someHeading = document.createElement('h1');
someHeading.innerText = 'This is a video';
// Append stuff to the new container
videoContainer.append(someHeading);
// Append the cloned video to the new container
videoContainer.append(videoClone);
// Remove the old video
videoElement.remove();
// Append your new video container with cloned video
document.body.append(videoContainer);
<video width="320" height="240" controls>
<source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
設(shè)置outerHTML
只會(huì)覆蓋 HTML。如果您想看到差異,您可以嘗試 和 的設(shè)置innerHTML
,outerHTML
但就您而言,結(jié)果可能相同。
- 1 回答
- 0 關(guān)注
- 98 瀏覽
添加回答
舉報(bào)