语法错误意外字符串

时间:2013-08-26 20:02:11

标签: string syntax-error

我很难解决这个字符串问题

contentString = '<div id="infoHead">Drag me for new coordinates.</br></div>'+results[1].formatted_address+'<div id="latlng">'+
                                  'Latitude: '+dmsLat+'</br>'+'Longitude: '+dmsLng+'</div>'+'</br>'+'<a href="//www.youtube.com/embed/Mzja4le8htk"'
            + 'style="width=420px; height=315px"'
            + 'onclick=' + '"window.open(this.href,'rockclimbing','left=400,top=250,width=420,height=315,toolbar=1,resizable=0');return false;"'
            + '>Click here for more details</a>'

例如通过以下代码:

'"window.open(this.href,'rockclimbing','left=400,top=250,width=420,height=315,toolbar=1,resizable=0');return false;"'

它显示了一些错误,其中rockclimbingleft until sizeable=0开始无法进行单一的quatotion。

那么如何解决这个问题呢? 我无法提供链接,因为这是我的第二个项目。任何形式的帮助我真的很感激。

2 个答案:

答案 0 :(得分:1)

你需要逃避内部引号:

'"window.open(this.href,\'rockclimbing\',\'left=400,top=250,width=420,height=315,toolbar=1,resizable=0\');return false;"'

否则rockclimbing之前的单引号会终止该字符串。

答案 1 :(得分:0)

我会告诉你如何找到你的错误。

我只是将我们的例子包括在第一个错误中。

当您将此片段移动到您的环境中时,如果

,此错误应该消失
results[1].formatted_address

可以转换为字符串。

在修复错误时移入越来越多的原始代码。

祝你好运!

错误报告的异常处理程序中包含的代码

try {
    contentString = '<div id="infoHead">Drag me for new coordinates.</br></div>'
    +results[1].formatted_address;
} catch(exception) {
    console.log(exception.stack);
}

用于错误诊断的控制台日志输出

ReferenceError: results is not defined
    at <anonymous>:2:84
    at Object.InjectedScript._evaluateOn (<anonymous>:580:39)
    at Object.InjectedScript._evaluateAndWrap (<anonymous>:539:52)
    at Object.InjectedScript.evaluate (<anonymous>:458:21)
相关问题