SCRIPT1002:语法错误,第1行字符6。

时间:2022-05-14 22:43:09

In the IE developer (F12) console, I've managed to get my pages to run without errors; all but one!

在IE developer (F12)控制台中,我成功地使页面运行无误;只有一个!

SCRIPT1002: Syntax error 
mypage.php, line 1 character 6

I am using IE9. Whats it's problem?

我使用IE9。什么是问题?

This is my code:

这是我的代码:

<!DOCTYPE html>
<head>
    <script type='text/javascript' src='/files/jquery-1.7.2.min.js'></script>
    <script type="text/javascript">
    $(document).ready(function() {
            $("#donateButton").click(function() {
                    alert('hey');
            });
    });
    </script>
</head>
<body>
    <a href="javascript:void();" id="donateButton">asdsadasd</a>
</body>

When I click on #donateButton, an error is produced. However, when I change javascript:void() to # then no error occurs any more. Why?

当我点击#donateButton时,会产生一个错误。但是,当我更改javascript:void()到#之后,就不会再有错误了。为什么?

2 个解决方案

#1


16  

"WAIT... does IE9 not like <a href="javascript:void();" id="donateButton"> ?? It seems thats the problem..?"
Comment by Chud37

“等等……难道IE9不喜欢 ?看来这就是问题所在。——评论Chud37

Yes, that is the problem. void is an operator, not a function. Use javascript:void 0 , javascript:void(0) or #. Even better, add event.preventDefault() to your function:

是的,这就是问题所在。void是一个运算符,而不是函数。使用javascript:void 0, javascript:void(0)或#。更好的是,在函数中添加event.preventDefault():

$('#donateButton').click(function(ev) {
    ev.preventDefault();
    alert('hello');
});

#2


-2  

The error might stem from the space you have between function and ()

错误可能源于函数和()之间的空间

try this

试试这个

<script type='text/javascript' src='files/jquery-1.7.2.min.js'></script>

    <script type="text/javascript">
    $(document).ready(function() {

        $('#donateButton').click(function() {
            alert('hello');     
        });
    });

    </script>

#1


16  

"WAIT... does IE9 not like <a href="javascript:void();" id="donateButton"> ?? It seems thats the problem..?"
Comment by Chud37

“等等……难道IE9不喜欢 ?看来这就是问题所在。——评论Chud37

Yes, that is the problem. void is an operator, not a function. Use javascript:void 0 , javascript:void(0) or #. Even better, add event.preventDefault() to your function:

是的,这就是问题所在。void是一个运算符,而不是函数。使用javascript:void 0, javascript:void(0)或#。更好的是,在函数中添加event.preventDefault():

$('#donateButton').click(function(ev) {
    ev.preventDefault();
    alert('hello');
});

#2


-2  

The error might stem from the space you have between function and ()

错误可能源于函数和()之间的空间

try this

试试这个

<script type='text/javascript' src='files/jquery-1.7.2.min.js'></script>

    <script type="text/javascript">
    $(document).ready(function() {

        $('#donateButton').click(function() {
            alert('hello');     
        });
    });

    </script>