有人可以帮助我完成这项工作:
我有一个非重复数组的复选框。如果选中复选框以删除重复项,则它可以正常工作,但如果我取消选中remove duplicates
,则复选框仍会删除重复项。
我想让它以如下方式工作:如果未选中(删除重复项)复选框,则在不删除重复项的情况下提取所有电子邮件。
感谢。
答案 0 :(得分:0)
您只需几行...当您输出电子邮件时,您需要检查确定是否应使用所有电子邮件或唯一(不重复)电子邮件的字段:
<script type="text/javascript">
function findEmail() {
var email = "No email address detected";
var a = 0;
var ingroup = 0;
var separator = document.extractor.sep.value;
var groupby = Math.round(document.extractor.groupby.value);
var outputEmails = [];
if (separator == "new") separator = "\n";
if (separator == "other") separator = document.extractor.othersep.value;
//match the email pattern in large text pasted in textarea.
var rawemail = document.extractor.rawdata.value.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi);
var norepeat = new Array();
if (rawemail) {
for (var i=0; i<rawemail.length; i++) {
var repeat = 0;
// Check for repeated emails routine
for (var j=i+1; j<rawemail.length; j++) {
if (rawemail[i] == rawemail[j]) {
repeat++;
}
}
// Create new array for non-repeated emails
if (repeat == 0) {
norepeat[a] = rawemail[i];
a++;
}
}
// For output, use all or unique (non-repeated) emails?
outputEmails = document.extractor["non-repeated"].checked ? norepeat : rawemail;
if( document.extractor["sortbox"].checked ) {
outputEmails = outputEmails.sort();
}
email = "";
// Join emails together with separator
for (var k = 0; k < outputEmails.length; k++) {
if (ingroup != 0) email += separator;
email += outputEmails[k];
ingroup++;
// Group emails if a number is specified in form. Each group will be separate by new line.
if (groupby) {
if (ingroup == groupby) {
email += '\n\n';
ingroup = 0;
}
}
}
}
// Return array length
var count = norepeat.length;
// Print results
document.extractor.count.value = count;
document.extractor.rawdata.value = email;
}
</script>
JSFiddle示例:https://jsfiddle.net/jimbo2150/ucvLtsts/21/