Javascript .click()中的jQuery函数等

Javascript .click()中的jQuery函数等,javascript,jquery,function,Javascript,Jquery,Function,所以通常我是这样做的: $('#selectRoom a').click( function(e) { e.preventDefault(); // To prevent the default behavior (following the link or adding # to URL) // Do some function specific logic here }); function selectRoom(e) { // now e will work } 然而,我想这样做

所以通常我是这样做的:

$('#selectRoom a').click( function(e) { 
e.preventDefault(); // To prevent the default behavior (following the link or adding # to URL)
// Do some function specific logic here
});
function selectRoom(e) {
  // now e will work
}
然而,我想这样做,清理东西(并能够重用):

问题是,我无法将“e”事件处理程序传递给函数,然后在加载时调用selectRoom()函数。i、 e:

$('#selectRoom a').click( selectRoom(e) );
我能以某种方式解决此问题吗?

selectRoom()将获得以下事件:

功能选择房间(e)

应该可以。将为selectRoom()提供以下事件:

功能选择房间(e)

这应该行得通。

这样声明:

$('#selectRoom a').click( function(e) { 
e.preventDefault(); // To prevent the default behavior (following the link or adding # to URL)
// Do some function specific logic here
});
function selectRoom(e) {
  // now e will work
}
不要这样做:

$('#selectRoom a').click(selectRoom(e)); // WRONG DO NOT DO THIS
因为这意味着,“调用函数selectRoom,然后将其返回值传递给jQuery中的“click”函数。”您希望传递给jQuery函数的名称,而不是执行函数的结果。因此:

$('#selectRoom a').click(selectRoom);
声明如下:

$('#selectRoom a').click( function(e) { 
e.preventDefault(); // To prevent the default behavior (following the link or adding # to URL)
// Do some function specific logic here
});
function selectRoom(e) {
  // now e will work
}
不要这样做:

$('#selectRoom a').click(selectRoom(e)); // WRONG DO NOT DO THIS
因为这意味着,“调用函数selectRoom,然后将其返回值传递给jQuery中的“click”函数。”您希望传递给jQuery函数的名称,而不是执行函数的结果。因此:

$('#selectRoom a').click(selectRoom);

您还可以从函数返回false以防止事件继续冒泡。

您还可以从函数返回false以防止事件继续冒泡