如何使用 jQuery 遍历页面中的所有 iframe 元素?
jqueryweb developmentfront end technology
要遍历页面中的所有 iframe 元素,请使用 jQuery 的 each() 方法。您可以尝试运行以下代码来学习如何遍历所有 iframe。我们在下面创建了三个 iframe。
示例
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("iframe").each(function(){
alert($(this).text())
});
});
});
</script>
</head>
<body>
<iframe src="https://www.qries.com">Qries Q/A</iframe>
<iframe src="https://tutorialspoint.com">Tutorialspoint Free Learning</iframe>
<iframe src="https://sendfiles.net">Send Files</iframe><br>
<button>Loop through iFrames</button>
</body>
</html>

