问题描述
在IE开发者(F12)控制台中,我设法让我的网页无误地运行;$ b
我正在使用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()
更改为#
时,不会再有错误发生。为什么?
是的,表示是问题所在。 是运算符,不是函数。使用 javascript:void 0
, javascript:void(0)
或#
。更好的是,添加添加到你的函数中:
$ $ 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!
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?
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!