【发布时间】:2014-06-02 05:32:09
【问题描述】:
由于某种原因,\n 在 javascript 中不适合我。无论如何要修复它或使用html?就我而言,我认为在我的href 中使用<br> 将不起作用。你有什么建议。
工作 JSFiddle here.
HTML:
<a id = 'emailoff' href = "" target = "_blank">
<div id= "btn1">
<h2 id = "enter">Send Email</h2>
</div>
</a>
Javascript:
$('#btn1').click(function() {
$("#emailoff").attr("href", "mailto:" +
"?subject=Your ThinOptics glasses" +
"&body=To get your new ThinOptics glasses simply click this link and pick the case and color you like best. You'll get free shipping on your order. \n"+
" WWw.Thinoptics.Com/teddy@shalon.com \n" +
"\n Enjoy")
});
【问题讨论】:
-
\n在 JavaScript 中确实有效。但是您的问题是 href 得到多线您正确想要的是转义新行,以便邮件客户端获得\n并可以将其视为\n:TLDR:使用\\n,但支持可能因客户端而异客户。 -
这可能会回答你的问题stackoverflow.com/questions/1155678/…
-
@NULL "\\n" 似乎不起作用...您的意思是用“\\n”替换“\n”吗?
-
你没有在你的href中动态插入任何东西,那么为什么不在渲染页面时插入href属性呢?
-
@JonathanAnctil 成功了!谢谢!!
标签: javascript jquery html