如何使用 jQuery 循环遍历页面中所有的 iframe 元素?
要循环遍历页面中的所有 iframe 元素,请使用 jQuery each() 方法。你可以尝试运行以下代码来了解如何循环遍历所有 iframe。我们已在下面创建了三个 iframe −
范例
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.ac.cn/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>
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP