I have an HTML table that's populate based upon information in a database, and want to have, at the bottom of the table, a button that, when clicked, opens up an email client (ala an HTML mailto:) and has multiple addresses in the TO: field that are based on certain cells in the table.
我有一个基于数据库中的信息填充的HTML表,并且希望在表的底部有一个按钮,当单击该按钮时,会打开一个电子邮件客户端(一个HTML mailto :)并且有多个地址TO:字段,基于表中的某些单元格。
I have the HTML for the button.
我有按钮的HTML。
<input type="button" id="emailAll" value="Email All">
And I started on this little piece of code to gather the email addresses when the button is clicked:
我开始使用这段代码来点击按钮时收集电子邮件地址:
$("emailAll").click(function($){
var emailCell = 4;
var length = document.getElementById("orgTable").rows.length;
var emailArray = [];
for (i = 0; i < length; i++) {
emailArray.push(document.getElementById("orgTable").rows[i].cells[emailCell].value);
}
});
However, I'm not really sure where to go from here. I've read that it's bad-form(?) to have multiple email addresses in a mailto:, so I'm not really sure where I should go from here? Also, I'm not even sure if the code as I currently have it will work (for example, I'm pretty sure the "emailAll" part is wrong?), so any correction would be appreciated! =]
但是,我不确定从哪里开始。我已经读过,在mailto:中有多个电子邮件地址是错误的形式(?),所以我不确定我应该从哪里开始?另外,我甚至不确定我现在拥有的代码是否可行(例如,我很确定“emailAll”部分是错误的?),所以任何更正都会受到赞赏! =]
Also, sorry if this has been asked before.
另外,如果之前有人询问过,请对不起。
Thanks!
EDIT So here's a few more details, because the answer I have right now unfortunately isn't working.
编辑所以这里有一些细节,因为我现在的答案不幸的是没有用。
This is being used on a wordpress site, and the code needs to be called from inside a post. When I try to use the code I have, a bunch of HTML tags are added into the source, such as </p>
, etc. this leads me to believe that even in the non-visual mode for the WordPress editor, that the formatting is still being applied. How would I work around this?
这是在wordpress网站上使用,需要从帖子内部调用代码。当我尝试使用我的代码时,会在源代码中添加一堆HTML标记,例如 等。这使我相信即使在WordPress编辑器的非可视模式下,格式仍在应用中。我该如何解决这个问题?
Also consider that I can't put the script in the of my HTML.
还要考虑我不能把脚本放在我的HTML中。
EDIT 2
Okay, so here's the code for the table. I'm using it in a Formidable Pro (a Wordpress Form Plug-in), so the [number] correspond to a field.
好的,所以这是表格的代码。我在Formidable Pro(Wordpress Form插件)中使用它,因此[number]对应于一个字段。
<div class = "fullWidth">
<table id = "orgTbl">
<thead id = "orgheader">
<tr>
<th class="orgheadercell" colspan = "5">[get-team]</th>
</tr>
<tr>
<th> ... </th>
<th> ... </th>
<th> ... </th>
<th> ... </th>
<th> Email Address </th>
</tr>
</thead>
<tbody id="orgbody">
<tr class = "orgbodyrow">
<td class="orgbodycell">[249]</td>
<td class="orgbodycell">[250]</td>
<td class="orgbodycell">[322]</td>
<td class="orgbodycell">[336]</td>
<td class="orgbodycell">[264]</td>
</tr>
</tbody>
<tr>
<td class="orgheadercell" colspan = "5">
<form id="getEmails" action="" method="GET">
<input type="submit" id = "emailAll" value="Email All" />
</form>
<script src = "/wp-includes/js/create-email.js" type="text/javascript">
</script>
</td>
</tr>
</table>
</div>
So, what you're looking at is a work-in-progress, still have to clean it up a bit before it's ready to go. But anyways, as I was saying, the [number] field is replaced with the actual value held in that, and the content between the <tbody>
and </tbody>
is repeated for each entry in my database.
所以,你所看到的是一项正在进行中的工作,在它准备好之前还需要对它进行一些清理。但无论如何,正如我所说,[number]字段被替换为其中保存的实际值,并且对于我的数据库中的每个条目重复和 之间的内容。
Also, I realize my script had "orgTable" listed, but I changed it to the correct "orgTbl". Additionally, as I thought value
would give me the value in the cell, and it apparently is for drop down menus, I changed that to innerHTML
. Still no luck though.
此外,我意识到我的脚本已列出“orgTable”,但我将其更改为正确的“orgTbl”。另外,正如我认为值会给我单元格中的值,并且它显然是用于下拉菜单,我将其更改为innerHTML。虽然还没有运气。
1 个解决方案
#1
1
Put your button inside a form like this:
将您的按钮放在这样的表单中:
<form action="" method="GET">
<input type="submit" value="Email All" />
</form>
For javascript, onload, put this:
对于javascript,onload,把这个:
$("emailAll").click(function($){
var emailCell = 4;
var length = document.getElementById("orgTable").rows.length;
var emailArray = [];
for (i = 0; i < length; i++) {
emailArray.push(document.getElementById("orgTable").rows[i].cells[emailCell].value);
}
// once you got your array of email properly from your table, try this
$('form').get(0).setAttribute('action', "mailto:"+emailArray.toString());
});
Edit: I forgot to add mailto: to make the action act like mailto link in href attribute.
编辑:我忘了添加mailto:使动作像href属性中的mailto链接一样。
#1
1
Put your button inside a form like this:
将您的按钮放在这样的表单中:
<form action="" method="GET">
<input type="submit" value="Email All" />
</form>
For javascript, onload, put this:
对于javascript,onload,把这个:
$("emailAll").click(function($){
var emailCell = 4;
var length = document.getElementById("orgTable").rows.length;
var emailArray = [];
for (i = 0; i < length; i++) {
emailArray.push(document.getElementById("orgTable").rows[i].cells[emailCell].value);
}
// once you got your array of email properly from your table, try this
$('form').get(0).setAttribute('action', "mailto:"+emailArray.toString());
});
Edit: I forgot to add mailto: to make the action act like mailto link in href attribute.
编辑:我忘了添加mailto:使动作像href属性中的mailto链接一样。