如何在 2 秒后更改 iframe 的 src 属性
您可以使用 JavaScript 来实现这个功能。下面是一个示例代码:
<!DOCTYPE html>
<html>
<head>
<title>Change iframe src after 2 seconds</title>
<script>
setTimeout(function() {
var iframe = document.getElementById('myIframe');
iframe.src = 'https://www.example.com';
}, 2000);
</script>
</head>
<body>
<iframe id='myIframe' src='about:blank'></iframe>
</body>
</html>
在这个示例中,我们首先通过 document.getElementById 获取到 id 为 'myIframe' 的 iframe 元素,然后使用 setTimeout 函数设置一个 2 秒的延迟,之后在延迟结束后将 iframe 的 src 属性设置为 'https://www.example.com'。
原文地址: https://www.cveoy.top/t/topic/mcqd 著作权归作者所有。请勿转载和采集!