繁体   English   中英

提取输出时如何防止预填充输入字段中的换行符消失? (JS)

[英]How to prevent line breaks in pre-filled input field from disappearing when extracting its output? (JS)

目前在做一个关于创建在线邮件应用程序的 JS 项目时遇到了一个问题。

对于每封电子邮件,都会有一个回复电子邮件按钮,单击该按钮将运行 reply_email 功能。 如下所示,此函数将使用 compose_email 函数,其中输入字段为发件人(预先填写为登录的人)、收件人、主题和正文。 对于这个reply_email 函数,它将预先填写收件人为上一封电子邮件的发件人,发件人为您。 对于正文,它会将上一封电子邮件的正文放在此回复电子邮件的下方。

function reply_email(email) {
  // use the compose email template
  compose_email();

  // set the recipient of the reply email as the sender of the original email
  document.querySelector('#compose-recipients').value = email['sender'];
  
  // set the subject of the reply email as 'Re: ' and then the subject of the original email, if a 'Re: ' isn't already there
  if (email['subject'].split(" ", 1)[0] != "Re:") {
    document.querySelector('#compose-subject').value = `Re: ${email['subject']}`;
  } else {
    document.querySelector('#compose-subject').value = email['subject'];
  }

  // can pre-load the values ok, but when submit all the spacing and blank lines in between all disappear. how to fix?
  document.querySelector('#compose-body').value = `\n \n \n On ${email['timestamp']}, \n <${email['sender']}> wrote: \n      ${email['body']}`;

}

如 image_1 所示,在 reply_email 模板中,正文部分看起来不错,前一封电子邮件在几行之后。 但是,在成功发送回复后,所有的行空间都会在查看单个电子邮件页面中消失,如图 2 所示。

在此处输入图像描述

在此处输入图像描述

任何人都知道问题可能是什么? 目前相当卡在这部分。

任何帮助将不胜感激。 谢谢!

结果当输出我使用'innerHTML'的文本值时,它应该是'innerText'。

感谢那些花时间阅读本文的人。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM