2011-12-30 132 views
1

此代码在wordpress以外的环境中工作正常,但Wordpress显示follwing错误并且什么也不做。任何人都可以说出原因吗? 由于未捕获的SyntaxError:意外的令牌ILLEGAL Wordpress

Uncaught SyntaxError: Unexpected token ILLEGAL custom_params.js:2Uncaught TypeError: Object # has no method 'prettyPhoto' chrome-extension://mpcddcfoblbgmnaklcpkbfajnfikinhn/videodownload.js:5Uncaught TypeError: Cannot read property '0' of null 3/wordpress/?page_id=458:169Uncaught ReferenceError: addInput is not defined

<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> 

回答

2

Uncaught SyntaxError: Unexpected token ILLEGAL

由非法字符/符号引起的。通常在行尾处有一个隐形字符。尝试检查custom_params.js第2行的无效字符。

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

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

相关问题