使用jQuery将单个事件处理程序绑定到多个事件

我有以下div为onblur,onmousedown,onmouseup和onfocus提供不同的函数。我想最小化代码,并且在div中只有一个函数调用所有函数状态。 我想用jquery这样做,换句话说。 我想创建一个名为functionAll的函数,并将所有的function1放入函数4,其中包含鼠标状态,然后在Div中使用functionAll。 我怎么能这样做?

test test

你应该在div上加上一个id,说“test”,然后:

 $('#test').bind('blur mousedown mouseup focus', function (e) { // This is your combined function // Inside here you can use e.type to find out whether it was a // "blur", "mousedown", "mouseup", etc... }); 

HTML将如下所示:

 
test test