简体   繁体   中英

Javascript syntax error - missing )

I keep getting an error in Firebug regarding the onClick event.

I've tried various different combinations of " and ' but to no avail. This worked fine before the onClick event was added.

Can anybody spot what I might be doing wrong?

addPhoneLogo: function (n) {
    if (i.phoneLogoLink.length > 1) var t = e('<span style="position:absolute; top:10px; right:10px;"><a onclick="ga('
    send ', '
    event ', '
    Call tracking ', '
    Click to call ', '
    Menufication ');"  href="' + phoneNum + '"><img src="' + i.phoneLogo + '" id="menufication-phone-logo" /></a></span>');
    else var t = e('<span style="position:absolute; top:10px; right:10px;"><a href="' + phoneNum + '"><img src="' + i.phoneLogo + '" id="menufication-phone-logo" /></a></span>');
    n.append(t)
},

Use escape character to add single quotes for onclick parameters : Use \\' instead of '

addPhoneLogo: function(n) {
             if (i.phoneLogoLink.length > 1) var t = e('<span style="position:absolute; top:10px; right:10px;"><a onclick="ga(\'send\', \'event\', \'Call tracking\', \'Click to call\', \'Menufication\');"  href="' + phoneNum + '"><img src="' + i.phoneLogo + '" id="menufication-phone-logo" /></a></span>');
             else var t = e('<span style="position:absolute; top:10px; right:10px;"><a href="' + phoneNum + '"><img src="' + i.phoneLogo + '" id="menufication-phone-logo" /></a></span>');
             n.append(t)
         },

Escape the ' by using \\

addPhoneLogo: function (n) {
    if (i.phoneLogoLink.length > 1)
        var t = e('<span style="position:absolute; top:10px; right:10px;"><a onclick="ga(\'send \', \'event\',\'       Call tracking \', \'Click to call \', \'Menufication \');"  href="' + phoneNum + '"><img src="' + i.phoneLogo + '" id="menufication-phone-logo" /></a></span>');
    else
        var t = e('<span style="position:absolute; top:10px; right:10px;"><a href="' + phoneNum + '"><img src="' + i.phoneLogo + '" id="menufication-phone-logo" /></a></span>');
    n.append(t)
},
addPhoneLogo: function (n) {
    if (i.phoneLogoLink.length > 1)
        var t = e('<span style="position:absolute; top:10px; right:10px;"><a onclick="ga(\'send \', \'event\',\'       Call tracking \', \'Click to call \', \'Menufication \');"  href="' + phoneNum + '"><img src="' + i.phoneLogo + '" id="menufication-phone-logo" /></a></span>');
    else
        var t = e('<span style="position:absolute; top:10px; right:10px;"><a href="' + phoneNum + '"><img src="' + i.phoneLogo + '" id="menufication-phone-logo" /></a></span>');
    n.append(t)
},

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM