比如:$("#goTopBtn").click(function () {
var sc = $(window).scrollTop();
$('body,html').animate({ scrollTop: 0 }, 500);
})
alert(sc);外面怎么获取到sc的值
直接获取获取不了,但是js的匿名函数支持闭包,你可以定义在外面
var sc = 0;
$("#goTopBtn").click(function () {
sc = $(window).scrollTop();
$('body,html').animate({ scrollTop: 0 }, 500);
})
while (sc==0);
alert(sc);
作用域和闭包问题:https://blog.csdn.net/hu_belif/article/details/80177952