我有以下 div,具有不同的 onblur、onmousedown、onmouseup 和 onfocus 功能。我想最小化代码,并且在 div 内只有一个函数调用来处理所有函数状态。我想用 jquery 来做到这一点 所以换句话说。我想创建一个名为 functionAll 的函数,并将所有 function1 放入 function 4 中,其中包含鼠标状态,然后只需在 Div 中使用 functionAll 即可。我怎样才能做这样的事情?
<div contentEditable="true"
onblur="function1();"
onmousedown="return function2(event);"
onmouseup="function3();"
onfocus="function4();">
test test
</div>
你应该在 div 上放置一个 id,说“测试”,然后:
$('#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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)