Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图在页面加载时运行一些 javascript。问题是当页面通过链接加载时$(window).load(function()不会触发。如果我直接加载页面,它会按预期工作。我怎样才能解决这个问题?谢谢您的帮助。
$(window).load(function()
window当您单击链接时,您可能不会导致重新加载 - 可能是由于异步调用。如果您想在click编辑链接时启动一些代码,您需要处理该click事件。
window
click
$('a#someLinkId').on('click', function(){ });
或者,如@KevinB 所述,在成功完成 AJAX 调用时执行您的代码。
$.ajax({ url: "someserverresource.html" }).done(function() { yourClientSideLogic(); });