如何在页面加载后使用 javascript 修改 html
how to modify html using javascript after the page loads
我是 js 新手,正在学习如何使用 js 修改 html,我想修改:
<video controls="" controlslist="download" src="//storage.googleapis.com/media-session/caminandes/short.mp4#t=80"><</video>
到...
<video controls="" controlslist="nodownload" src="//storage.googleapis.com/media-session/caminandes/short.mp4#t=80">< </video>
页面加载后,我想将 controlslist="download"
更改为 controlslist="nodownload"
页面来源:https://googlechrome.github.io/samples/media/controlslist.html
像下面这样使用 onload
事件
window.onload = function() {
// select your expected video tag
// change attribute controlslist value to expected one
}
完整代码:
window.onload = function() {
// select your expected video tag
// change attribute controlslist value to expected one
var searchString = "t=80";
var videos = document.getElementsByTagName("video");
for (let item of videos) {
if (item.getAttribute("src").includes(searchString)) {
item.setAttribute("controlslist", "Anything I want")
}
}
}
我是 js 新手,正在学习如何使用 js 修改 html,我想修改:
<video controls="" controlslist="download" src="//storage.googleapis.com/media-session/caminandes/short.mp4#t=80"><</video>
到...
<video controls="" controlslist="nodownload" src="//storage.googleapis.com/media-session/caminandes/short.mp4#t=80">< </video>
页面加载后,我想将 controlslist="download"
更改为 controlslist="nodownload"
页面来源:https://googlechrome.github.io/samples/media/controlslist.html
像下面这样使用 onload
事件
window.onload = function() {
// select your expected video tag
// change attribute controlslist value to expected one
}
完整代码:
window.onload = function() {
// select your expected video tag
// change attribute controlslist value to expected one
var searchString = "t=80";
var videos = document.getElementsByTagName("video");
for (let item of videos) {
if (item.getAttribute("src").includes(searchString)) {
item.setAttribute("controlslist", "Anything I want")
}
}
}