2015-11-04 126 views
0

在我的html表單中,我有一個增加html表格行的javascript功能。但不知何故,它在控制檯日誌返回錯誤:爲什麼控制檯日誌顯示「Uncaught SyntaxError:Unexpected token ILLEGAL」錯誤消息?

以下是錯誤消息: 未捕獲的SyntaxError:意外的標記非法

這裏是截圖: enter image description here

這裏是JS我正在使用的代碼:

// add more email number 
$(document).ready(function() { 
    var max_fields = 4; //maximum input boxes allowed 
    var wrapper = $("#emailWraper"); //Fields wrapper 
    var add_button = $("#addMoreEmail"); //Add button ID 

    var x = 1; //initlal text box count 
    $(add_button).click(function(e) { //on add input button click 
     e.preventDefault(); 
     if (x < max_fields) { //max input box allowed 
      x++; //text box increment 

      <?php $sql = mysqli_query($link, 'SELECT * FROM contact_type'); ?> 

      $(wrapper).append("<tr id='deleteEmail'><td align='right' style='padding-right:10px;'><select name='phoneExt[]'><option value=''>--select--</option><?php while($result_ctype = mysqli_fetch_array($sql)){ $ctid = (int) $result_ctype['ctid']; $all_Contact_type = inputvalid($result_ctype['contact_type']); echo " < option value = $ctid > "; echo $all_Contact_type; echo '</option>';}?></select></td><td align='right'><input type='text' name='' class='small3' id='' placeholder='Value'/><a href='#' class='remove_field'>&nbsp;X</a></td></tr>"); //add input box*/ 
     } 
    }); 

    $(wrapper).on("click", ".remove_field", function(e) { //user click on remove text 
     e.preventDefault(); 
     $("#deleteEmail").remove(); 
     x--; 
    }) 
}); 

你能告訴我爲什麼它顯示在我的代碼中嗎?

更新: HTML代碼:

<table width="290" border="0" cellpadding="0" cellspacing="0" id="emailWraper"> 
    <tr><td>Email <a href="#" id="addMoreEmail">(+)</a></td><td>&nbsp;</td></tr>  
    <tr> 
    <td align="right">Work :</td> 
    <td id="mailto" align="right"><input value="<?php echo $email; ?>" type="text" name="email" 
id="email" placeholder="work email"/></td> 
    </tr> 

    <tr> 
    <td align="right">Private :</td> 
    <td align="right"><input value="<?php echo $email_private; ?>" type="text" name="email_private" id="email_private" placeholder="private email"/></td> 
    </tr> 
    </table> 

控制檯在Firebug:代碼enter image description here

+0

您有一個PHP代碼在這裏。確保它是一個PHP文件,並且此代碼正在執行,但未打印出來。 –

+0

請注意,如果這是一個JS文件,他們不能解釋PHP代碼,並因此給出錯誤。 –

+0

順便說一下,在您的控制檯中,當您遇到錯誤時,您可以點擊'VB1720:159'並查看實際的錯誤原因。 –

回答

1

檢查是否有一些非法chacters像空格,空值等,

檢查here獲得更多答案。

有些用戶建議刪除代碼的最後一行並重新添加它即可解決此問題。

相關問題