未捕获的SyntaxError:意外的令牌ILLEGAL Wordpress

时间:2011-12-30 13:42:34

标签: wordpress

此代码在wordpress之外工作正常,但Wordpress显示以下错误并且什么都不做。有人能说出原因吗? 感谢

  

未捕获的SyntaxError:意外的令牌ILLEGAL   custom_params.js:2 Uncaught TypeError:Object#没有方法   'prettyPhoto'   镀铬的扩展://mpcddcfoblbgmnaklcpkbfajnfikinhn/videodownload.js:5Uncaught   TypeError:无法读取null的属性“0”   3 / wordpress /?page_id = 458:169未捕获的ReferenceError:addInput不是   定义

<script type="text/javascript">
var counter = 1;
var limit = 3;
function addInput(divName){
     if (counter == limit)  {
          alert("You have reached the limit of adding " + counter + " inputs");
     }
     else {
          var newdiv = document.createElement('div');
          newdiv.innerHTML = "Entry " + (counter + 1) + " <br><input type='text' name='myInputs[]'>";
          document.getElementById(divName).appendChild(newdiv);
          counter++;
     }
}
</script>
<form method="POST">
     <div id="dynamicInput">
          Entry 1<br><input type='text' name='myInputs[]'>
     </div>
     <input type='button' value='Add another text input' onClick='addInput("dynamicInput")'>
</form>

1 个答案:

答案 0 :(得分:2)

  

未捕获的SyntaxError:意外的标记ILLEGAL

是由非法字符/符号引起的。通常是行尾的隐形字符。请尝试检查custom_params.js第2行是否包含无效字符。

这篇文章有一个很好的例子: Uncaught SyntaxError: Unexpected token ILLEGAL for Chrome Browser

将代码片段复制粘贴到记事本中,你会看到一个额外的“?”代码段末尾的字符。