通过Java脚本在HTML部分中添加背景视频

问题描述

你好!我正在尝试在WordPress网站上的部分中添加背景视频。我无法编辑该页面代码,所以我必须通过JavaScript添加它。这是网站页面链接http://listchicagocondo.com/index.php/new-form/。在第一部分背景中,我想添加视频

我尝试添加jQuery属性,但是没有用。

解决方法

尝试此操作,您可以根据需要添加更多属性

<script>
window.addEventListener('load',(event) => {
// Create the text node for video element.
    var video = document.createElement('video');  
  // Create the text node for source element.
     var source = document.createElement('video');  
//add id attribute on video tag    
    video.setAttribute('id','video');

    source.src='video.mp4';
      video.appendChild(source);
    
});
</script>