简体   繁体   English

JavaScript错误,但看不出原因

[英]JavaScript errors, but can't see why

I'm running a very simple piece of code to increment a number in a stats file. 我正在运行一段非常简单的代码来增加stats文件中的数字。

It works, but testing it in various IE versions I get the following errors. 它工作,但在各种IE版本测试它我得到以下错误。 I got inconsistent performance from IE7 and 9 and I think this might be causing it. 我从IE7和9获得了不一致的性能,我认为这可能会导致它。

I'm getting a syntax error on the following piece of script. 我在下面的脚本上遇到语法错误。

<script type="text/javascript">

 function updateLikeCount(){

     parent.increment('likelinkspace14', <!--#include file="14stats.txt"-->, ' Likes');

}  <------------- *I get the error on this line*
</script>

And I'm also getting an error stating object expected in the following: 而且我也收到一个错误,说明预期的对象如下:

<body leftmargin="0" topmargin="0" onload="updateLikeCount();">

replace 更换

parent.increment('likelinkspace14', <!--#include file="14stats.txt"-->, ' Likes');

with

parent.increment('likelinkspace14', '<!--#include file="14stats.txt"-->', ' Likes');

Assuming the code in the question is server side code rather than the code that gets delivered to the client the answer depends on the code being included. 假设问题中的代码是服务器端代码而不是传递给客户端的代码,答案取决于所包含的代码。

As others have pointed out, wrapping the include output in quotes might help: 正如其他人所指出的那样,将include输出包装在引号中可能会有所帮助:

parent.increment('likelinkspace14', '', ' Likes'); parent.increment('likelinkspace14','','喜欢');


This line has a double comma: 这一行有一个双逗号:

parent.increment('likelinkspace14', <!--#include file="14stats.txt"-->, ' Likes');

Without the html comment: 没有html评论:

parent.increment('likelinkspace14', , ' Likes');

The problem is in the second parameter because is without ' 问题出在第二个参数,因为没有'

Javascript parameter without ' is like a variable 没有'的Javascript参数就像一个变量

try this: 尝试这个:

<script type="text/javascript">
 function updateLikeCount(){
     parent.increment('likelinkspace14', '<!--#include file="14stats.txt"-->', ' Likes');
}  
</script>

Fron inside a script tag <!--#include file="14stats.txt"--> is considered syntax error. 脚本标记内的Fron <!--#include file="14stats.txt"-->被视为语法错误。

Well, not quite syntax error but it is not a comment. 好吧,不是语法错误,但它不是评论。 Inside a script tag it is interpreted as: 在脚本标记内,它被解释为:

< // less than
! // boolean inversion
-- // decrement

Since there's nothing on the left of the < operator it generates an error (among many other things which may also generate errors). 由于<运算符左侧没有任何内容,因此会产生错误(在许多其他可能也会产生错误的事情中)。

The problem is because of string parameter . 问题是因为string parameter You are trying to add a string parameter without quotes 您正在尝试添加不带quotes的字符串参数

try this 尝试这个

parent.increment('likelinkspace14', '<!--#include file="14stats.txt"-->', ' Likes');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM