简体   繁体   English

我可以通过 Javascript 设置 HTML 视频属性吗?

[英]Can I set HTML video attributes via Javascript?

I'm wanting to set attributes to HTML videos via (vanilla) Javascript.我想通过(香草)Javascript 将属性设置为 HTML 视频。 My platform is Tumblr, and as such I am unable to set the attributes directly to the video tag.我的平台是 Tumblr,因此我无法将属性直接设置为视频标签。

I'm currently using the script below, which works perfectly on most browsers (chrome, firefox and edge) but not on IE (and I am unable to check Safari at this stage).我目前正在使用下面的脚本,该脚本在大多数浏览器(chrome、firefox 和 edge)上都能完美运行,但在 IE 上却不行(在这个阶段我无法检查 Safari)。 Using a script validator, I believe my problem is the "fat arrow" ( => ) syntax.使用脚本验证器,我相信我的问题是“胖箭头”( => )语法。

document.querySelectorAll('video').forEach((v) => {v.autoplay = false; v.muted = false; v.volume = 0.5; v.preload = false; v.loop = true;});

My biggest issue is because I have all my scripts merged into one, the "error" in the video script breaks all my other scripts (on IE).我最大的问题是因为我将所有脚本合并为一个,视频脚本中的“错误”破坏了我所有其他脚本(在 IE 上)。

Is there a way I can replace the "fat arrow", or is there another way to go about setting video attributes via Javascript?有没有办法可以替换“胖箭头”,或者是否有另一种方法可以通过 Javascript 设置视频属性?

Is there a way I can replace the "fat arrow",有没有办法可以替换“胖箭头”,

Can't you just convert it to a regular anonymous function?你不能把它转换成一个普通的匿名 function 吗?

.forEach(function(v) {v.autoplay = false; v.muted = false; v.volume = 0.5; v.preload = false; v.loop = true;})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM