SCRIPT1002:语法错误,第1行字符6 [英] SCRIPT1002: Syntax Error, Line 1 Character 6

查看:4722
本文介绍了SCRIPT1002:语法错误,第1行字符6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在IE开发者(F12)控制台中,我设法让我的网页无误地运行;
$ b


  SCRIPT1002:语法错误
mypage.php,第1行字符6


我正在使用IE9。



这是我的代码:

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

当我点击#donateButton时,会产生错误。但是,当我将 javascript:void()更改为时,不会再有错误发生。为什么?

解决方案


WAIT ... IE9不像< ; a href =javascript:void();id =donateButton> ??看起来就是这个问题..?

Chud37评论


是的,表示是问题所在。 void 运算符不是函数。使用 javascript:void 0 javascript:void(0)。更好的是,添加 event.preventDefault() 添加到你的函数中:

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


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?

解决方案

"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');
});

这篇关于SCRIPT1002:语法错误,第1行字符6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆