How to call function declared in $(document).ready()?
I have the following code:
$(document).ready(function() {
var refresh = function() {
alert('doing!');
}
}
How to call refresh()开发者_JS百科
function outside the $(document).ready()
? Anywhere in the jQuery functions?
eg.
$('#el').click() {
document.ready().refresh();
}
There isn't a way to call a method defined in a more local scope from another, you have to either store a reference to it, or declare it at/in a higher scope, for example:
$(document).ready(function() {
window.refresh = function() {
alert('doing!');
};
});
Or:
var refresh = function() {
alert('doing!');
};
$(document).ready(function() {
//other code...
});
精彩评论