Ada*_*dam 3 javascript jquery javascript-events
我有一个div有大量的儿童div(大约4k-5k!).每个孩子都有一个'mousedown'和'mouseup'连接到它的事件.
我是否应该将这些事件一次性附加到父母并选择孩子使用$(e.target)?是否会有任何性能优势,如果是这样,为什么?
谢谢!
我想可以使用jquery.on()是理想的.
$("#divWithHugeAmountsOfChildDiv").on("mousedown",
".childCLASSEStoMouseDown",
function()
{
alert("Booya!");
});
Run Code Online (Sandbox Code Playgroud)
你的html可能是这样的:
<body>
<!-- lots of other elements -->
<div id="divWithHugeAmountsOfChildDiv">
<!-- lots of different type of elements -->
<div class="childCLASSEStoMouseDown">Booya?</div>
<!-- lots of different type of elements -->
</div>
<!-- lots of other elements -->
</body>
Run Code Online (Sandbox Code Playgroud)
根据需要更改jQuery选择器...
为什么在该On方法的jQuery文档中得到了很好的解释.
| 归档时间: |
|
| 查看次数: |
4497 次 |
| 最近记录: |