当我运行网站时,它会显示“错误:未终止的字符串常量”。它所说的代码就是问题:
var icsdate = currentDate.getFullYear() + currentDate.getMonth() + currentDate.getDate() + "T" + currentDate.getHours() + currentDate.getMinutes() + currentDate.getSeconds() + "Z";
完整的脚本是:
<script type="text/javascript">
var currentDate = new Date();
var icsdate = currentDate.getFullYear() + currentDate.getMonth() + currentDate.getDate() + "T" + currentDate.getHours() + currentDate.getMinutes() + currentDate.getSeconds() + "Z";
var inonehour = currentDate.getHours() + 1;
var icsenddate = currentDate.getFullYear() + currentDate.getMonth() + currentDate.getDate() + "T" + inonehour + currentDate.getMinutes() + currentDate.getSeconds() + "Z";
var location = "USA"
var msgData1 = icsdate;
var msgData2 = icsenddate;
var msgData3 = location;
var icsMSG = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//Our Company//NONSGML v1.0//EN\nBEGIN:VEVENT\nUID:me@google.com\nDTSTAMP:20120315T170000Z\nATTENDEE;CN=My Self ;RSVP=TRUE:MAILTO:me@gmail.com\nORGANIZER;CN=Me:MAILTO::me@gmail.com\nDTSTART:" + msgData1 +"\nDTEND:" + msgData2 +"\nLOCATION:" + msgData3 + "\nSUMMARY:Our Meeting Office\nEND:VEVENT\nEND:VCALENDAR";
$('.button').click(function () {
window.open("data:text/calendar;charset=utf8," + escape(icsMSG));
});
</script>
答案 0 :(得分:0)
location
是JavaScript中的只读属性您单独列出的确切代码行不会给出“错误:未终止字符串常量”错误消息,但是指定var location = "USA"
在全局范围内将尝试覆盖只读window.location
对象,并尝试将浏览器重定向到页面/USA
,我想这可能会影响您的代码。
您应该将location
重命名为其他内容。
例如,在Chrome中运行以下代码段...
var location = "USA";
...将给出以下错误消息:
在其他浏览器中,它可能会抛出不同的错误,例如您正在使用的浏览器上获得的错误。