意外的令牌ILLEGAL

时间:2014-04-17 13:54:03

标签: javascript jquery html

我遇到了代码问题。我想编辑一个元素的href。我需要它来点击预先制作的主题和正文时发送你的电子邮件。我收到了错误"意外的令牌ILLEGAL"虽然我完全不确定为什么。

我希望有人可以帮我解决这个问题。

我需要在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")
            });

更新:

错误在:&#34; mailto:email@email.com ...&#34;

1 个答案:

答案 0 :(得分:8)

您不能在javascript字符串中包含换行符,这会导致未终止的文字,从而导致错误。为便于阅读,请使用:

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

或类似。

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

相关问题