你能帮帮我吗... 如何从jquery函数返回变量
var height = $(window).height();
$(window).resize(function(){
var height = $(window).height();
return height;
});
setInterval(function() {
$('div').append( 'Index: ' + height );
}, 500);
最佳答案
你不需要回来。试试这个:
var height = $(window).height(); // define "height" here
$(window).resize(function(){
height = $(window).height(); // update "height" variable,
// don't user "var" here.
// because using "var" will redefine
// "height" again and no longer contain the
// updated value on window resize
// out of this resize function scope
});
setInterval(function() {
$('div').append( 'Index: ' + height );
}, 500);
关于javascript - 如何从jquery函数返回变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12431241/