gpt4 book ai didi

javascript - 意外的 token 非法

转载 作者:行者123 更新时间:2023-11-28 11:35:21 25 4
gpt4 key购买 nike

我的代码遇到了问题。我想编辑元素的 href。当我点击预制的主题和正文时,我需要它来发送打开您的电子邮件。我收到错误“意外的 token 非法”,但我完全不知道为什么。

我希望有人能帮助我解决这个问题。

我需要在 javascript 中编辑此属性,因此将其放在开始元素中是行不通的!

有一个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: 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")
});

更新:

错误位于:“mailto: email@email.com...”

最佳答案

JavaScript 字符串中不能有换行符,否则会产生未终止的文字,从而导致出现错误。为了便于阅读,请使用:

"mailto: email@email.com" +
"?subject=Your thinoptics glasses " +
"body=To get your new thinoptics glasses"

或类似的。

编辑:如果需要换行,请在字符串内使用 \n

关于javascript - 意外的 token 非法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23135096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com