当事件被触发并且页面更新同时发生时会发生什么? [英] What happens when an event is triggered and page update both take place at the same time?
问题描述
鉴于我有这样的HTML:
Given I have HTML like this:
<a id="google" href="http://google.com">Google.com</a>
和这样的Javascript:
And Javascript like this:
$('#google').on('click', function (e) {
console.log("Click Click Bang Bang!");
});
当我点击 google
链接时, 点击
事件触发,页面会立即加载下一个链接...
When I click my google
link, the click
event fires and the page immediately loads the next link…
如果目标网址会有什么变化(google.com )在点击事件结束之前加载?如果事件只是触发并完成而不管可查看的页面更新/更改URL /等,那就太棒了!但如果不是这样,你如何确保你的点击
事件运行完成?
What happens if the target URL (google.com) loads before the click event finishes? If events just fire and complete irrespective of the viewable page updating/changing urls/etc then that's awesome! BUT if that's not the case, how do you ensure your click
event runs to completion?
谢谢!
推荐答案
console.log是同步
调用和页面重定向后完成点击事件。如果你有异步
在中点击
,那么你必须注意你必须在离开之前等待回应页面。
The console.log is synchronous
call and page is redirected after the completion of the click event. If you have asynchronous
call in the click
event then you have to take care that your have to wait for response before leaving the page.
这篇关于当事件被触发并且页面更新同时发生时会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!