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

我有以下div与onblur,onmousedown,onmouseup和onfocus不同的功能。我想最小化代码,只有一个函数调用内部的div所有的功能状态。我想用jquery做这个,所以换句话说。我想创建一个名为functionAll的函数,把所有的function1都放在函数4里,里面有鼠标,然后在Div里面使用functionAll。我该怎么做这样的事情?
<div contentEditable="true"
     onblur="function1();"
     onmousedown="return function2(event);"
     onmouseup="function3();"
     onfocus="function4();">
    test test
</div>

解决方法

你应该把一个id放在div上,说“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将如下所示:

<div id="test" contentEditable="true">
    test test
</div>

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...