[英]jQuery array populating mailto link adding commas
I have a list of links to pdfs. 我有一个pdf链接列表。 Users can check a checkbox for each pdf, and then submitting the form will launch an email (using mailto:) with the items they have selected. 用户可以选中每个pdf的复选框,然后提交表单将启动一个电子邮件(使用mailto :)以及他们选择的项目。
Everything works fine, except in the body of the email, the selected pdfs array are separated by a comma, so the comma is appearing in the email body. 一切正常,除了在电子邮件正文中,选定的pdfs数组用逗号分隔,因此逗号出现在电子邮件正文中。
Can anyone please help me get rid of the comma that separates them? 任何人都可以帮我摆脱分隔他们的逗号吗?
Tina 蒂娜
Update your script like below and let me know if it works, 像下面一样更新你的脚本,让我知道它是否有效,
$('#send-email').submit(function(){
var selectedpdfs = '';
$('#send-email input:checkbox:checked').each(function(i){
// All selected pdfs: gets link's text and link's url
selectedpdfs += $(this).prev().text() + '%0a' + $(this).prev().attr('href') + '%0a%0a'
});
//alert(selectedpdfs);
window.location.href = 'mailto:?subject=Materials&body='+selectedpdfs
return false;
});
Note: I modified selectedpdfs to a string object and changed it to string concatenation. 注意:我将selectedpdfs修改为字符串对象并将其更改为字符串连接。
Array to String -> will return you a comma separated list of string. Array to String - >将返回逗号分隔的字符串列表。
use join()
on the array to concatenate them into a string, you may speicfy which character to delimit. 在数组上使用join()
将它们连接成一个字符串,你可以指定要分隔的字符。
eg selectedpdfs.join(' ')
will return a string delimited by a space. 例如, selectedpdfs.join(' ')
将返回由空格分隔的字符串。
see http://jsfiddle.net/qiao/HmWf3/1/ for a live demo 请参阅http://jsfiddle.net/qiao/HmWf3/1/进行现场演示
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.