2014-02-05 47 views
0

我收到未捕獲的SyntaxError:意外的令牌鉻非法使用此代碼:未捕獲的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

缺少'}''後的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"; }'; 
相關問題