Reputation: 744
Here is my code:
<input id="m" autocomplete="off"/>
and I put the following lines in script
$('#m').on('blur', alert('blurred'););
$('#m').on('focus', alert('focused'););
The result is, it will pop up 'blurred' when the page starts. But afterward, it no longer fires the alert('blurred')
.
More interesting is, the focus()
works well.
Thanks for any suggestion or help.
Upvotes: 0
Views: 303
Reputation: 67505
You should create a function then pass it as parameter :
$('#m').on('blur', blurred);
function blurred(){
alert('blurred');
}
Hope this helps.
Upvotes: 2
Reputation: 413682
The .on()
method requires that you pass it a function. You're passing the return value of a call to alert()
.
$('#m').on('blur', function() { alert('blurred'); });
That code creates a simple anonymous function that makes your alert()
call.
Upvotes: 4