Javascript 语法错误

Javascript Syntax error

我正在尝试为我的一个客户在 Javascript 商店查找器上设置一个 google 跟踪事件。我已经在 "submit button" 上进行了事件跟踪,效果很好。地图上的每个商店都有一个 link 以获取更多信息。我正在尝试为 "More information" link 设置一个事件,以便它显示哪个商店的点击次数最多。

出于某种原因,我在 link 中使用 OnClick 事件通过 Google 事件跟踪代码后立即收到错误消息。以下是包含商店详细信息的部分:

 var contentString =
    '<div id="content" style="height:150px"><div id="bodyContent"><span style="font-weight:bold; font-size: 14px">' +
    location[0] + '</span><br /><br />' + location[1] + '<br />' + location[2] + ', ' + location[3] + ' ' + 
    location[4] + '<br /><br /><a href="contractordetail.aspx?id=' + 
    location[8] + '&zip=' + $("#ctl00_Body_ctl00_zip").val() +'" >More information</a>&nbsp;&nbsp;-&nbsp;&nbsp;<a href="http://maps.google.com/maps?daddr=' + location[1] + '+' + location[2] + '+' + location[3] + '+' + location[4] + '&hl=en&vpsrc=0&mra=ls&z=4" target="_blank">Get Directions</a><br /></div></div>';
    var infowindow = new google.maps.InfoWindow({ content: contentString, maxWidth: 300 });
    google.maps.event.addListener(marker, 'click', function () {
        infowindow.open(map, marker);
    });

上面的代码工作正常,但是当我尝试放置 Onclick 事件时,出现错误:

    var contentString =
    '<div id="content" style="height:150px"><div id="bodyContent"><span style="font-weight:bold; font-size: 14px">' +
    location[0] + '</span><br /><br />' + location[1] + '<br />' + location[2] + ', ' + location[3] + ' ' + 
    location[4] + '<br /><br /><a onclick="ga('send', 'event', { eventCategory: 'Contractor Search', eventAction: 'Submit', eventLabel: 'Search Contractors'});" href="contractordetail.aspx?id=' + 
    location[8] + '&zip=' + $("#ctl00_Body_ctl00_zip").val() +'" >More information</a>&nbsp;&nbsp;-&nbsp;&nbsp;<a href="http://maps.google.com/maps?daddr=' + location[1] + '+' + location[2] + '+' + location[3] + '+' + location[4] + '&hl=en&vpsrc=0&mra=ls&z=4" target="_blank">Get Directions</a><br /></div></div>';
    var infowindow = new google.maps.InfoWindow({ content: contentString, maxWidth: 300 });
    google.maps.event.addListener(marker, 'click', function () {
        infowindow.open(map, marker);
    });

请注意,第二个代码在我的 "More Information" link 上有一个 onclick 事件。这是我每次尝试使用 onclick 事件时都会出错。我在它周围使用了单个代码来消除错误,但是搜索没有成功。

非常感谢任何帮助! 谢谢,

已解决!我必须转义事件跟踪块代码中的所有单引号。谢谢vp_arth