2013-09-23 98 views
1

我有一個使用cloudsponge導入聯繫人的小部件。他們設置了它,以便將所有內容導入到文本字段中。我希望將所有內容都放入兩個輸入字段中。雲海綿回電。

他們向我發送了這段代碼,並表示可以修改它以將聯繫人放入輸入文件夾中,但我無法弄清楚如何執行此操作。

<!DOCTYPE html> 
<html> 
<body> 
<a class="cs_import">Add from Address Book</a> 
<textarea id="contact_list" style="width:450px;height:82px"></textarea> 

<script type='text/javascript'> 
// these values will hold the owner information 
var owner_email, owner_first_name, owner_last_name; 
var appendInTextarea = true; // whether to append to existing contacts in the textarea 
var emailSep = ", "; // email address separator to use in textarea 
function populateTextarea(contacts, source, owner) { 
    var contact, name, email, entry; 
    var emails = []; 
    var textarea = document.getElementById('contact_list'); 

    // preserve the original value in the textarea 
    if (appendInTextarea && textarea.value.strip().length > 0) { 
    emails = textarea.value.split(emailSep); 
    } 

    // format each email address properly 
    for (var i = 0; i < contacts.length; i++) { 
    contact = contacts[i]; 
    name = contact.fullName(); 
    email = contact.selectedEmail(); 
    entry = name + "<" + email +">"; 
    if (emails.indexOf(entry) < 0) { 
     emails.push(entry); 
    } 
    } 
    // dump everything into the textarea 
    textarea.value = emails.join(emailSep); 

    // capture the owner information 
    owner_email = (owner && owner.email && owner.email[0] && owner.email[0].address) || ""; 
    owner_first_name = (owner && owner.first_name) || ""; 
    owner_last_name = (owner && owner.last_name) || ""; 
} 

// Replace the domain_key and stylesheet with valid values. 
var csPageOptions = { 
    domain_key:"YOUR_DOMAIN_KEY", 
    afterSubmitContacts:populateTextarea 
}; 
</script> 
<script type="text/javascript" src="https://api.cloudsponge.com/address_books.js"></script> 
</body> 
</html>**strong text** 

回答

1

你可以嘗試像它增加了一個文本字段,nameemail對於被選中的每個聯繫人下面。請注意,它會在div內添加字段,而不是在textarea中放置大字符串。

<!DOCTYPE html> 
<html> 
<body> 
<a class="cs_import">Add from Address Book</a> 
<div id="contacts-div"></div> 

<script type='text/javascript'> 
// these values will hold the owner information 
var owner_email, owner_first_name, owner_last_name; 

function createInput(parent_id, name, value) { 
    var input = document.createElement('input'); 
    input.type = 'text'; 
    input.value = value; 
    input.name = name; 
    document.getElementById(parent_id).appendChild(input); 
} 

function populateTextarea(contacts, source, owner) { 
    var contact, name, email; 
    // Create an input for each name and email address 
    for (var i = 0; i < contacts.length; i++) { 
    contact = contacts[i]; 
    name = contact.fullName(); 
    email = contact.selectedEmail(); 
    createInput('contacts-div', 'name' + i, name); 
    createInput('contacts-div', 'email' + i, email); 
    } 
} 

// Replace the domain_key and stylesheet with valid values. 
var csPageOptions = { 
    domain_key:"YOUR_DOMAIN_KEY", 
    afterSubmitContacts:populateTextarea 
}; 
</script> 
<script type="text/javascript" src="//api.cloudsponge.com/address_books.js"></script> 
</body> 
</html> 

警告:我爲CloudSponge工作。 :)