通过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>