2017-04-19 110 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

相关问题