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);
});
加载中,请稍侯......
精彩评论