Simple jQuery .change question
I am new to jQuery and am having difficulty getting a .change event to call a named func开发者_运维技巧tion. When I use an anonymous function, it works fine.
This works fine:
$(function() {
$("select").change(function() {
alert("hello");
});
});
This does not work (i.e. has not effect):
$(function() {
$("select").change(processSelection());
function processSelection() {alert('Hello!');};
});
Any assistance much appreciated!
You are passing the function as an argument, not calling it, so you don't need the ()
after processSelection
. So, you should do
$("select").change(processSelection);
instead of
$("select").change(processSelection());
精彩评论