我想在slideUp函数之后加载文件(使用href变量),而不是之前。
我的代码:
$(document).ready(function() {
$("#content").show().load($(".link2:first").attr('href'));
$(".link").click(function() {
var href = $(this).attr('href');
$("#content").slideUp("slow");
$("#content").slideDown("slow").load(href);
return false;
});
});
和 HTML:
<a href="testar2.html" class="link">Link 1</a>
<a href="testar.html" class="link">Link 2</a>
<div id="content">-</div>
有什么想法可以解决这个问题吗?
最佳答案
使用这个:
$("#content").slideUp("slow", function(){
$(this).load(href, function (responseText, status, req) {
if (status != "error") $(this).slideDown("slow");
});
});
我还添加了错误检查,以防 .load()
失败。
关于javascript - `.load`完成后执行函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16984539/