开发者

jQuery Binding Woes

I have a function:

function foo() { console.log('i run!'); }

And a binding to a button:

$(function() { 
   $('#myButton'开发者_开发技巧).click(foo);
});

I am almost positive that the console should not show 'i run!' until the button is clicked. I have no other #myButtons on the page (I have forple checked this), and yet foo continues to run when another unrelated button is clicked. There are no other references to foo (again, forple checked).

What could be happening here? Am I binding wrong?


You're not closing you're document ready block properly, it is missing a closing parenthesis (and optionally a semicolon), try:

$(function() { 
   $('#myButton').click(foo);
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜