2017-04-19 78 views
0
我有兩個問題snipet

如何與郵寄地址在發送郵件提交

1) for some reason the body is not updating with the innerHTML of #test 

2) The client's email is coming up on the SHARE link but I can't get it to open on submit 

function Mailto_url(){ 
 
\t var encode_mailto_component = function(str){ 
 
\t \t try{ return encodeURIComponent(str); } 
 
\t \t catch(e){ return escape(str); } 
 
\t } 
 
\t var AddressList = function(){ 
 
\t \t var list = []; 
 
\t \t this.length = 0; 
 
\t \t this.add = function(address){ 
 
\t \t \t if(address) { 
 
\t \t \t \t list.push(address); 
 
\t \t \t \t this.length = list.length; 
 
\t \t \t } 
 
\t \t }; 
 
\t \t this.get = function(){ 
 
\t \t \t return list.join(';'); 
 
\t \t }; 
 
\t }; 
 
\t var subject = '', 
 
\t \t body = '', 
 
\t \t mainList = new AddressList(), 
 
\t \t ccList = new AddressList(), 
 
\t \t bccList = new AddressList(); 
 
\t this.setSubject = function(str){ subject = encode_mailto_component(str); } 
 
\t this.setBody = function(str){ body = encode_mailto_component(str); } 
 
\t this.addMain = function(x) { mainList.add(x); } 
 
\t this.addCC = function(x) { ccList.add(x); } 
 
\t this.addBCC = function(x) { bccList.add(x); } 
 
\t this.getURL = function(allow_empty_mainList){ 
 
\t \t var out = ['mailto:']; 
 
\t \t var extras = []; 
 
\t \t if(mainList.length === 0 && !allow_empty_mainList){ 
 
\t \t \t throw('Mailto_url: no main addressees'); 
 
\t \t } 
 
\t \t else{ 
 
\t \t \t out.push(mainList.get()); 
 
\t \t } 
 
\t \t if(subject) { extras.push('subject=' + subject); } 
 
\t \t if(ccList.length) { extras.push('cc=' + ccList.get()); } 
 
\t \t if(bccList.length) { extras.push('bcc=' + bccList.get()); } 
 
\t \t if(body) { extras.push('body=' + body); } 
 
\t \t if(extras.length) { out.push('?' + extras.join('&')); } 
 
\t \t return out.join(''); 
 
\t } 
 
} 
 

 
function getContent() { 
 
\t var mailTo = new Mailto_url(); 
 
    var test = document.getElementById('test'); 
 
mailTo.addMain('[email protected]'); 
 
mailTo.addMain('[email protected]'); 
 
mailTo.addCC('[email protected]'); 
 
mailTo.addCC('[email protected]'); 
 
mailTo.addBCC('[email protected]'); 
 
mailTo.addBCC('[email protected]'); 
 
mailTo.setSubject("test"); 
 
mailTo.setBody(test.innerHTML); 
 
window.location=mailTo.getURL(true); 
 
\t \t 
 
\t 
 
}
<html> 
 

 
<body> 
 
    <div id="wrapper"> 
 

 

 
    <form> 
 
     <ul> 
 
     <li> 
 
      <a class="home" href="#"></a> 
 
     </li> 
 
     <li><a id="share" class="share" href="#" onclick="getContent()">Share Quote</a></li> 
 
     <li> 
 
      <a class="info" href="#"></a> 
 
     </li> 
 
     <li><input id='test' type='text'></input> 
 
     </li> 
 
     <li><input type='submit' onclick="getContent()"></input> 
 
     </li> 
 
     </ul> 
 
    </form> 
 
    </div> 
 

 

 
</body> 
 

 
</html>

回答

2

第2部分

<form onsubmit="return false"> 

改變這一行

+0

它確實工作!謝謝 – DCR

+0

請標記爲答案 – xxLITxx

+0

它也沒有行Mailto_url();在sendMail函數中。你能解釋爲什麼當我調用一個調用它的函數的函數時,但是直接調用它卻不行?另外,無論如何,如果沒有文本添加所需的彈出窗口顯示? – DCR

2
mailTo.setBody(test.value); 

它不應該的innerHTML它應該是值。 另外,您發佈的代碼中沒有函數調用。

+0

謝謝。關於第二個問題的任何想法? – DCR

+0

請再解釋一下這個問題。當我添加一個函數調用時,電子郵件對話框出現了。 – xxLITxx

+0

提交按鈕上的函數調用似乎不起作用。你在哪裏或如何添加函數調用? – DCR

相關問題