Lia*_*lon 0 html javascript jquery
我的代码遇到了问题.我想编辑一个元素的href.我需要它来点击预先制作的主题和正文时发送你的电子邮件.我收到错误"Unexpected token ILLEGAL"但我完全不确定原因.
我希望有人可以帮我解决这个问题.
我需要在javascript中编辑这个属性,所以把它放在要开始的元素中是行不通的!
有一个的jsfiddle 这里.
这是我的:
HTML:
<a id = 'emailoff' href = "" target = "_blank">
<div id= "btn1">
<h2 id = "enter">Send Email</h2>
</div>
</a>
Run Code Online (Sandbox Code Playgroud)
JAVASCRIPT:
$('#btn1').click(function(){
$("#emailoff").attr("href", "mailto: email@email.com
?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
WWw.Thinoptics.Com/email@email.com
Enjoy")
});
Run Code Online (Sandbox Code Playgroud)
更新:
错误在:"mailto:email@email.com ......"
您不能在javascript字符串中包含换行符,这会导致未终止的文字,从而导致错误.为便于阅读,请使用:
"mailto: email@email.com" +
"?subject=Your thinoptics glasses " +
"body=To get your new thinoptics glasses"
Run Code Online (Sandbox Code Playgroud)
或类似的.
编辑:如果您需要换行符,请\n在字符串中使用.