[英]Jquery event like $(window).load for partial view
I have event that fires on window.load
我有在
window.load
上触发的事件
$(window).load(function () {...});
But I have logic on this page which update partial view. 但是我在此页面上具有更新局部视图的逻辑。 After this logic I also want to execute
window.load
. 在此逻辑之后,我还想执行
window.load
。
How can I do this? 我怎样才能做到这一点?
Document ready doens't help 准备好文档无济于事
Assuming that you're using jQuery's ajax to load the partial views: 假设您正在使用jQuery的ajax加载部分视图:
First, you'll want to separate out the code that happens on both full and partial loads: 首先,您要分离出在全部和部分加载中都发生的代码:
function OnLoadTasks() {
// stuff that happens on every load.
}
$(window).load(function () {
OnLoadTasks();
// Other stuff that only happens on full load, if any
});
Then you can easily call that function again later: 然后,您可以稍后轻松地再次调用该函数:
$.ajax(...)
.done(function(r) {
// Do whatever tasks need to be done to load the data
OnLoadTasks();
});
$.ajax() could also be one of the shortcuts, like $.get() or $.load() $ .ajax()也可以是快捷方式之一,例如$ .get()或$ .load()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.