[英]jQuery - Uncaught SyntaxError: Unexpected token )
I have - what I think - should be a very simple jquery
script. 我有-我认为-应该是一个非常简单的jquery
脚本。 When the register_hyperlink
anchor is clicked, I am presented with the alert
box, as expected; 单击register_hyperlink
锚点时,如预期的那样,向我显示了alert
框。 but after I click the OK, I am getting an error: Uncaught SyntaxError: Unexpected token )
但是单击“确定”后,出现错误: Uncaught SyntaxError: Unexpected token )
The code block is below. 代码块在下面。 I can't see anywhere that there are unbalanced parenthesis as the error states. 我看不到任何地方都有不平衡的括号作为错误状态。 The code below is inside the element of my html page. 下面的代码在我的html页面的元素内。
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#register_hyperlink").click(function() {
alert('Hello');
});
});
</script>
Does anyone have any idea how to go about debugging this? 有谁知道如何去调试它? I've been at it for a while now, but am having zero luck. 我已经有一段时间了,但是运气为零。
Thanks! 谢谢!
I had: 我有:
<a id="register_hyperlink" href="javascript:void();">Register an account</a>
I changed it to: 我将其更改为:
<a id="register_hyperlink" href="javascript:void(0);">Register an account</a>
So that explains it :-) 这样就可以解释了:-)
What have you got in the href attribute of your anchor? 您的锚的href属性有什么? Alternatively do you have a an onClick attribute in the anchor or are you catching it anywhere else? 另外,您在锚点中是否具有onClick属性,还是在其他任何地方捕获它?
You are not preventing the default behaviour of the anchor and you may have a syntax error in the href. 您没有阻止锚的默认行为,并且href中可能存在语法错误。 That would be my first guess. 那是我的第一个猜测。
You could change your posted function to: 您可以将发布的功能更改为:
$(document).ready(function () {
$("#register_hyperlink").click(function(e) {
e.preventDefault();
e.stopPropagation();
alert('Hello');
});
});
If you test with this function you may find, as Matt Ball points out that your problem was indeed elsewhere 如果您使用此功能进行测试,您可能会发现,正如Matt Ball指出的那样,您的问题确实存在于其他地方
你可以用
<a id="register_hyperlink" href="javascript:;">Register an account</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.