2015-11-04 128 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获得更多答案。

有些用户建议删除代码的最后一行并重新添加它即可解决此问题。

相关问题