我有以下代码:
$(document).ready(function() {
var refresh = function() {
alert('doing!');
}
}
如何在$(document).ready()
之外调用refresh()
函数? jQuery 函数中的任何位置?
例如。
$('#el').click() {
document.ready().refresh();
}
最佳答案
没有办法从另一个调用在更局部作用域中定义的方法,您必须存储对它的引用,或者在更高作用域/在更高作用域中声明它,例如:
$(document).ready(function() {
window.refresh = function() {
alert('doing!');
};
});
或者:
var refresh = function() {
alert('doing!');
};
$(document).ready(function() {
//other code...
});
关于javascript - 如何调用 $(document).ready() 中声明的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4569402/