javascript jQuery 错误:缺少(在形式参数之前
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5568529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery error: missing ( before formal parameters
提问by arame3333
I have this jQuery script:
我有这个 jQuery 脚本:
<script type="text/javascript">
$(document).ready(function{
$("#btnLogon").bind("click", function(){
$("#btnLogon").after('<span class="error">Please wait...</span>');
});
});
</script>
In Firebug I get the error message
在 Firebug 中,我收到错误消息
missing ( before formal parameters
What am I doing wrong here?
我在这里做错了什么?
回答by ThiefMaster
$(document).ready(function{
should be
应该
$(document).ready(function(){
回答by H?vard
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$("#btnLogon").bind("click", function(){
$("#btnLogon").after('<span class="error">Please wait...</span>');
});
});
</script>
You were missing the parentheses after function
, on the second line.
您function
在第二行中缺少 , 之后的括号。
回答by StuperUser
You're missing the empty parameter list in the anonymous function for the ready handler on the document.
您在文档上的就绪处理程序的匿名函数中缺少空参数列表。
You can also use click()
as a shortcut to bind()
.
You can also use event.target
in your handler function, rather than select from the DOM again.
您也可以event.target
在处理程序函数中使用,而不是再次从 DOM 中选择。
$(document).ready(function(){
$("#btnLogon").click(function(e){
$(e.target).after('<span class="error">Please wait...</span>');
});
});