admin管理员组

文章数量:1201572

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

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

I am using IE9. Whats it's problem?

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?

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

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

I am using IE9. Whats it's problem?

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?

Share Improve this question edited Jan 18, 2019 at 11:45 Rory McCrossan 338k41 gold badges319 silver badges350 bronze badges asked Jun 29, 2012 at 13:42 Chud37Chud37 5,00714 gold badges68 silver badges125 bronze badges 3
  • It's about line 1 of one of your <script> blocks I guess. – CodeCaster Commented Jun 29, 2012 at 13:44
  • okay, but then thats just: "$(document).ready(function () {" – Chud37 Commented Jun 29, 2012 at 13:46
  • 4 My psychic powers still lack the ability of remote debugging (I definitely should get that service pack installed one day). Please trim your HTML and JS down to a few lines where the error still occurs and then put the code in your question. It must be something like a missing parenthesis. – CodeCaster Commented Jun 29, 2012 at 13:50
Add a comment  | 

1 Answer 1

Reset to default 19

"WAIT... does IE9 not like <a href="javascript:void();" id="donateButton"> ?? It seems thats the problem..?"
— Comment by 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:

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

本文标签: javascriptSCRIPT1002 Syntax ErrorLine 1 Character 6Stack Overflow