我有一個包含 3 列電子郵件地址的 HTML 表格。我試圖弄清楚如何使用表單 action=mailto: 向表中的所有電子郵件地址發送大量電子郵件,并將該操作分配給 input type="submit" 按鈕. 基本上我正在尋找的是當我按下提交按鈕時,瀏覽器將打開我的電子郵件客戶端并在其中包含每個人的電子郵件地址。我想我必須為每個人的電子郵件地址分配某種 ID,因此當我按下按鈕時,表單將掃描表格以查找電子郵件地址以包含在電子郵件的“收件人”塊中。
這是一個例子:
<form action="mailto:?"method="get">
<table class="rep">
<th class="rep">Office</th>
<th class="rep">Primary Representative</th>
<th class="rep">Alternate Representative</th>
<th class="rep">Phone #</th>
<th class="rep">Pri. E-mail</th>
<th class="rep">Alt. E-mail</th>
<th class="rep">Supervisor</th>
<th class="rep">Sup. E-mail</th>
<tr class="rep">
<td class="rep">Mail Room</td>
<td class="rep">Harry Frill</td>
<td class="rep">Jack Daniels</td>
<td class="rep">123-456-7890</td>
<td class="rep"><a href="mailto:[email protected]">E-Mail</td>
<td class="rep"><a href="mailto:[email protected]">E-Mail</td>
<td class="rep">Lauren Jory</td>
<td class="rep"><a href="mailto:[email protected]">E-Mail</td>
</tr>
<tr class="rep">
<td class="rep">Labs</td>
<td class="rep">Jay Holiday</td>
<td class="rep">Tony Tarks</td>
<td class="rep">987-676-5432</td>
<td class="rep"><a href="mailto:[email protected]">E-Mail</td>
<td class="rep"><a href="mailto:[email protected]">E-Mail</td>
<td class="rep">Ben Dinkle</td>
<td class="rep"><a href="mailto:[email protected]">E-Mail</td>
</tr>
<input type="Submit" value="E-Mail all reps">
</table>
</form>
uj5u.com熱心網友回復:
我添加了一個按鈕以及一個事件偵聽器,當單擊該事件偵聽器時,它會遍歷所有<a>
標簽,提取他們的電子郵件地址,并創建一個mailto:
包含所有這些地址的 URL,并將用戶重定向到該 URL。
document.querySelector('button#doIt').addEventListener('click', function() {
var emails = []
document.querySelectorAll('a[href^="mailto:"]').forEach(function(elmt){
var email = elmt.getAttribute('href').replace(/^mailto:/, '')
emails.push(email)
});
document.location.href = 'mailto:' emails.join(',')
});
<table class="rep">
<tr>
<th class="rep">Office</th>
<th class="rep">Primary Representative</th>
<th class="rep">Alternate Representative</th>
<th class="rep">Phone #</th>
<th class="rep">Pri. E-mail</th>
<th class="rep">Alt. E-mail</th>
<th class="rep">Supervisor</th>
<th class="rep">Sup. E-mail</th>
</tr>
<tr class="rep">
<td class="rep">Mail Room</td>
<td class="rep">Harry Frill</td>
<td class="rep">Jack Daniels</td>
<td class="rep">123-456-7890</td>
<td class="rep"><a href="mailto:[email protected]">E-Mail</td>
<td class="rep"><a href="mailto:[email protected]">E-Mail</td>
<td class="rep">Lauren Jory</td>
<td class="rep"><a href="mailto:[email protected]">E-Mail</td>
</tr>
<tr class="rep">
<td class="rep">Labs</td>
<td class="rep">Jay Holiday</td>
<td class="rep">Tony Tarks</td>
<td class="rep">987-676-5432</td>
<td class="rep"><a href="mailto:[email protected]">E-Mail</td>
<td class="rep"><a href="mailto:[email protected]">E-Mail</td>
<td class="rep">Ben Dinkle</td>
<td class="rep"><a href="mailto:[email protected]">E-Mail</td>
</tr>
</table>
<button id="doIt">Do it!</button>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/504285.html
上一篇:如何將字串從函式中的catchlblock回傳到另一個檔案
下一篇:CSS中的條紋表