最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery error: missing ( before formal parameters - Stack Overflow

programmeradmin3浏览0评论

I have this jQuery script:

<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

missing ( before formal parameters

What am I doing wrong here?

I have this jQuery script:

<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

missing ( before formal parameters

What am I doing wrong here?

Share Improve this question edited Feb 25, 2014 at 19:41 Eric Leschinski 154k96 gold badges422 silver badges336 bronze badges asked Apr 6, 2011 at 15:00 arame3333arame3333 10.2k27 gold badges129 silver badges214 bronze badges 0
Add a comment  | 

3 Answers 3

Reset to default 15
$(document).ready(function{

should be

$(document).ready(function(){
<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.

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.

$(document).ready(function(){
    $("#btnLogon").click(function(e){
        $(e.target).after('<span class="error">Please wait...</span>');
    });
});
发布评论

评论列表(0)

  1. 暂无评论