是否可以以某种方式拦截 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/