2014-02-05 4 views
0

Я получаю неперехваченный SyntaxError: Неожиданный маркер НЕЗАКОННО в хроме с этим кодом:Uncaught SyntaxError: Неожиданный токен НЕЗАКОННО

var leftMiddleJS = 'function onmouseover() { 
     document.getElementById("background").style.marginTop = "-135px"; 
     document.getElementById("background").style.marginLeft = "0px"; 
     document.getElementById("background").style.width = "760px"; 
     document.getElementById("background").style.height = "520px"; 
     document.getElementById("background").style.marginTop = "0"; 
     document.getElementById("background").style.marginLeft = "0"; 

     function click() { 
     document.getElementById("outsideContainer").style.marginTop = "0"; 
     document.getElementById("outsideContainer").style.marginLeft = "0"; 
     document.getElementById("outsideContainer").style.width = "300px"; 
     document.getElementById("outsideContainer").style.height = "250px"; 
     document.getElementById("insideContainer").style.marginTop = "-135px"; 
     document.getElementById("insideContainer").style.marginLeft = "0px"; }'; 

В чем проблема с кодом?

+0

Его высказывание на первой линии – user2958098

+0

Missing '}' после 'document.getElementById («фона»). style.marginLeft = "0"; ' –

+0

Что вы делаете с цитатой в функции declration' 'function' onmouseover() –

ответ

1

Если вы хотите присвоить строку, которая охватывает несколько строк - использование \ строка продолжения:

var leftMiddleJS = 'function onmouseover() { \ 
     document.getElementById("background").style.marginTop = "-135px"; \ 
     document.getElementById("background").style.marginLeft = "0px"; \ 
     document.getElementById("background").style.width = "760px"; \ 
     document.getElementById("background").style.height = "520px"; \ 
     document.getElementById("background").style.marginTop = "0"; \ 
     document.getElementById("background").style.marginLeft = "0"; \ 
\ 
     function click() { \ 
     document.getElementById("outsideContainer").style.marginTop = "0"; \ 
     document.getElementById("outsideContainer").style.marginLeft = "0"; \ 
     document.getElementById("outsideContainer").style.width = "300px"; \ 
     document.getElementById("outsideContainer").style.height = "250px"; \ 
     document.getElementById("insideContainer").style.marginTop = "-135px"; \ 
     document.getElementById("insideContainer").style.marginLeft = "0px"; }'; 
Смежные вопросы