2012-10-24 27 views
2

我只是把一些HTML的變種,我得到這個錯誤:未捕獲 語法錯誤:意外的令牌非法未捕獲的SyntaxError:意外的標記非法當把HTML的變種

typeForm = "Type de RDV : <br />                                             
      <input type='radio' name='rdv-type' value='0' class='rdv-type' />Client seul<br />                              
      <input type='radio' name='rdv-type' value='1' class='rdv-type' />Client + con<br />                           
      <input type='radio' name='rdv-type' value='2' class='rdv-type' />Visite agence<br />                             
      <input type='radio' name='rdv-type' value='4' class='rdv-type' />Signature PV<br />                              
      <input type='radio' name='rdv-type' value='5' class='rdv-type' />Con step<br />                           
      <input type='radio' name='rdv-type' value='3' class='rdv-type' />Land analysis<br />"; 

我沒有得到什麼,我我做錯了。我在第一個<br />附近收到警告。

我查了其他帖子,但我真的不明白它爲什麼這樣做。

+0

您是否嘗試刪除部分字符串以確定哪個部分導致錯誤? –

+1

可能的重複[如何在JavaScript中的多行代碼中分割字符串?](http://stackoverflow.com/questions/508269/how-do-i-break-a-string-across-more -than-one-line-of-code-in-javascript) – Quentin

+0

@Quentin如果你不知道這是一個有問題的斷字符串,只有錯誤信息,你將永遠無法得到這個問題。 – Christoph

回答

7

這是因爲在JavaScript中你不能簡單地啓動一個字符串值的新行,您應該'逃避新行'

var smth = "Some text \ 
      continues here \ 
      and here"; 

或使用字符串連接:

var smth = "Some text " + 
      "continues here " + 
      "and here"; 
+0

啊,非常感謝。我對此一無所知。我是jQuery/js的新手,你先生教我一些我從未想到過的東西。 – Jp1987

+0

@ Jp1987不客氣! – VisioN

1
typeForm = "Type de RDV : <br/>" +                                             
     "<input type='radio' name='rdv-type' value='0' class='rdv-type' />Client seul<br />" +     
.... 

1

當斷行追加一個「+」你的HTML字符串格式不正確每個新行

+0

謝謝。我用VisioN解決方案,但這個工作非常好,謝謝:) – Jp1987

1

之前,串連所有行,使包括多行的字符串。

Live Demo

typeForm = "Type de RDV : <br /> " +                                             
      " <input type='radio' name='rdv-type' value='0' class='rdv-type' />Client seul<br />  " +                            
      " <input type='radio' name='rdv-type' value='1' class='rdv-type' />Client + con<br />  " +                          
      " <input type='radio' name='rdv-type' value='2' class='rdv-type' />Visite agence<br />  " +                            
      " <input type='radio' name='rdv-type' value='4' class='rdv-type' />Signature PV<br />   " +                           
      "<input type='radio' name='rdv-type' value='5' class='rdv-type' />Con step<br />   " +                         
    " <input type='radio' name='rdv-type' value='3' class='rdv-type' />Land analysis<br />"; 

    alert(typeForm); 
+0

Ty的協助:) – Jp1987

相關問題