如何创建一个全局变量来获取div的初始位置,甚至可以在所有函数中访问
$(document).bind('click', function (e) {
或者可以使用下面的函数
$(document).bind('click', function (e) { //blahblah });
在内部访问
$(document).ready(function(){});
最佳答案
在 document.ready 之外声明一个变量或将其附加到 window 对象。
var globalVariable;
$(document).ready(function(){
globaVariable = $("div").offset().top;
// set the position of div as you desire
});
否则使用window.globalVariable
$(document).ready(function(){
window.globaVariable = $("div").offset().top;
// set the position of div as you desire
});
关于javascript - jquery 全局变量可访问性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29691632/