开发者

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...
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜