开发者

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());
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜