gpt4 book ai didi

javascript - jQuery:拦截原始 DOM 就绪事件?

转载 作者:行者123 更新时间:2023-11-28 10:21:05 25 4
gpt4 key购买 nike

是否可以以某种方式拦截 DOM 就绪事件,以便通常在 $(document).ready(function() { ... } 内触发的任何内容都不会被执行?然后手动触发事件以便代码执行?

就我而言,我有大量现有代码已经依赖于 $(document).ready(function() { ... } 并且我希望我不会进行搜索/替换以使其全部依赖于自定义手动触发事件。

最佳答案

jQuery.trigger()就是为了这样的需要而生的

Any event handlers attached with .bind() or one of its shortcut methods are triggered when the corresponding event occurs. They can be fired manually, however, with the .trigger() method. A call to .trigger() executes the handlers in the same order they would be if the event were triggered naturally by the user:

关于javascript - jQuery:拦截原始 DOM 就绪事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5658774/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com