html——jquery 遍历方法each()的用法

通过jquery的选择器往往可以获取多个对象,each() 用于遍历这些对象。

函数原型:
$(selector).each(function(index,element))

html使用代码举例(点击按钮打印索引和元素):

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcss.com/jquery/3.5.0/jquery.js"></script>
    <script>

        $(function () {

            $("#sendBtn").click(function () {

                $(".addressInput").each(function (index, element) {
                    console.info(index);
                    console.info(element);
                });

            });

        })
    </script>

</head>
<body>


<label>
    发送邮箱名1<input class="addressInput" type="text">
</label>
<label>
    发送邮箱名2<input class="addressInput" type="text">
</label>
<label>
    发送邮箱名3<input class="addressInput" type="text">
</label>


<button id="sendBtn" >批量发送邮件</button>
</body>
</html>

参考https://www.w3school.com.cn/jquery/traversing_each.asp

发布了82 篇原创文章 · 获赞 14 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_35077107/article/details/105497036